Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8995

Re: Offline Data Chaching Problem in SMP 3.0 Android Native

$
0
0

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


Viewing all articles
Browse latest Browse all 8995

Trending Articles