Skip to Content
MBO Android App OData Android App

OData Android Content:

Device’s Local Database Creation

In this section, we will cover migration concepts involved in the creation of the device’s local database

In MBO based mobile apps, the device local database is automatically created when needed by the Object API. In addition, the generated package database class contains methods that allow programmers to delete or create a device’s local database manually.

In OData mobile apps, the device local database is created through the initialization of the Offline OData store. The Offline OData store is a class that represents a service endpoint that can be interacted via OData protocol. Please note the mobile app must have network connectivity to open a store for the first time. Subsequent attempts to open the store may be performed without network connectivity. The following flow diagram explains how the device local database is created during the initialization of the offline store. /wp-content/uploads/2015/06/createlocaldb_715283.jpg

Notice in the diagram that the mobile app requests the initial download with “defining requests”. The “defining requests” define the entire set of data that will be available offline. In this exercise we have created a custom class OfflineStoreManager to handle the offline store. Check the openOfflineStore method of this class, to understand how to set the defining requests and all other require information to open an offline store.

Developers must pay close attention to the way they set the defining request. For example, in order for entity relationships to be available on the client we need to use $expands in our defining requests. The $expand syntax is to name the navigation property that you want to expand, most OData producers do support $expand. For example:

options.addDefiningRequest(“reg1”, “BusinessPartners?$expand=SalesOrders/Items”, false);

Mobile apps can open an offline store synchronously and asynchronously. For asynchronous calls, we can create a custom class “EntityCollection” to handle the creation of the offline store and a listener class “OfflineStoreListener” that implements ODataOfflineStoreListener that can be called upon reaching each stage during the initialization of the store. The interface ODataOfflineStoreListener defines four methods:

  • offlineStoreNotification that is called once for each notification that is available while opening the store
  • offlineStoreOpenFailed, called if the store fails to open
  • offlineStoreOpenFinished called when the store finishes opening
  • offlineStoreStateChanged, called whenever the store state changes during the initialization and opening of the offline store. A successful sequence of state changes is: Opening -> Initializing -> Populating -> Downloading -> Open.


These classes would allow us to separate the backend requests from the user experience.


/wp-content/uploads/2015/06/createlocaldb2_750441.jpg

Please note we have submitted the sample application for publishing and it will be available in a Git repository soon

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply