on 07-25-2014 6:02 AM
Hi All, I am working on Offline features of SMP 3.0 Android, Saving data in Cache and syncing with backend when network available. Once I close all activities and login in online mode the Cache getting cleared and no data available in the cache.I am using SP03. Is there any issue with Libraries or is it the nature of libraries?? Please suggest me any alternative to work on this. Need suggestions on next versions for complete offline features.
The SMP Odata SDK provides the capability for client applications to cache the data on device when the mobile device is out of network and process it later when it is within the range of network. You need to use Cache APIs to do it. Make sure you added cache related libraries are included in the project (ex.cache,persistence,libdatabase_sqlcipher.so, libsqlcipher_android.so,guava,libstlport_shared.so).
In order to parse and build Odata entries Service document and metadata document are required. So on first registration of user with SMP server retrieve these documents and store it locally by leveraging Odata SDK Cache library.
Sample code to retrieve the service document from cache:
IODataServiceDocument serviceDocument = null;
try {
//Getting Service Document from the cache
serviceDocument =
(IODataServiceDocument)mApplication.getCache().readDocument(
DocumentType.ServiceDocument,
FlightModelConstants.FLIGHT_MODEL_SERVICE_DOCUMENT);
} catch (CacheException e) {
Log.v(TAG, e.getLocalizedMessage());
}
//Checking if Service Document was not found in cache,
if (serviceDocument == null) {
mProgress =
ProgressDialog.show(this,
(CharSequence) "",
(CharSequence)
getString(R.string.serviceDocumentProgress),
true);
mRequestTag = REQUEST_SERVICE_DOCUMENT;
//Preparing request to retrieve Service Document from the server
IRequest request =
RequestBuilder.getInstance().buildServiceDocumentRequest(this,
REQUEST_SERVICE_DOCUMENT);
//Sending the request
mApplication.getRequestManager().makeRequest(request);
} else {
Toast.makeText(this, R.string.msgServiceDocumentCache,
Toast.LENGTH_LONG).show();
//Service Document was in the cache, now we are going to retrieve the
Schema
this.getServiceSchema();
}
Code to be added in onSuccess callback method to store the document:
IODataServiceDocument serviceDocument = parser
.parseODataServiceDocument(responseString);
mApplication.getCache().storeDocument(serviceDocument,
DocumentType.ServiceDocument,
FlightModelConstants.FLIGHT_MODEL_SERVICE_DOCUMENT);
Code above is for storing service document; to store Metadata document above code is repeated once.
The above code shows how to store and retrieve service document and metadata document. Odata SDK also allows storing of Odata entries in cache and offline operation.
Midhun VP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.