Migration Step 3 – Read Operations (Android)
|MBO Android App||OData Android App|
OData Android Content:
- Device’s Local Database Creation
- Read Operations
- CUD Operations (Coming soon!)
In this section will cover how to access data from the device’s local database
In MBO based mobile apps, developers can use the find, findAll, or findByPrimaryKey methods in the MBO class
In OData based mobile apps, developers can access the local database when the offline store state is “Open”. The offline store does not provide methods like find, findAll or findByPrimaryKey, instead it provides methods to send GET request with filters in the URL to reduce the amount of data that will need to be displayed. For example the URL BusinessPartners?$filter=Country eq ‘US’ will retrieve the business partners located in the US.
The offline store offers both asynchronous and synchronous functions for OData operations. There are a variety of methods that developers can use to access data from the local database, in this case the OfflineStoreManager class is using store.scheduleRequest method to send an asynchronous GET request. This method receives:
- A request: represented by ODataRequestParamSingle class that defines a single request used to perform a CRUD operation. In consequence store.scheduleRequest method can be used to send not only GET request, but also POST, PUT and DELETE requests.
ODataRequestParamSingle request = new ODataRequestParamSingleDefaultImpl();
offlineStore.scheduleRequest (request,requestListener );
- A OfflineRequestListener that implements ODataRequestListener interface. This listener can be called upon reaching each stage of the request. Various methods are invoked at key events by the OData Store implementation:
- requestStarted: Request has been started.
- requestServerResponse: Server response has been received
- requestFailed: OData request has been failed.
- requestFinished: OData request has been finished
Below there’s a diagram that show the flow for asynchronous GET request to access data from the device local database.
Please note we have submitted this sample app for publishing and it will be available in a Git repository soon.