cancel
Showing results for 
Search instead for 
Did you mean: 

Offline Data Chaching Problem in SMP 3.0 Android Native

Former Member
0 Kudos

  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.  

Accepted Solutions (1)

Accepted Solutions (1)

midhun_vp
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi midhun, Thanks for the reply. I was succeed up to creating,updating and deleting in offline mode. It working fine till  the application in Active mode.Once I just close my application and login again I cannot find stored data in Cache.Its clears all the data.

midhun_vp
Active Contributor
0 Kudos

You mean to say that you are killing the application and running the app resulting in lose of data ? Are you sure that you are retrieving the stored data the way I given (mApplication.getCache().readDocument)?

Midhun VP

Answers (0)