4

I am building an android application, which involves listing details of product. These products will be 500 to 1000 items and evolve over time, with changes from backend server.

To avoid fetching this large data from server each time to display list, need to persist in local database and display by querying from database.

For persisting data, i explored the following ways available.

  1. Native sqlite (sync using sync adapter framework)
  2. Realm (couldn't figure how to sync)
  3. Couchbase lite (has it's own sync gateway)

But yet couldn't come into any conclusion for best possible approach.

Since the data is large and we need to have offline access to data through app, syncing data becomes very important. I am still learning these things.

Can someone please guide me in the right direction to design storing data and syncing data when there is some change in backend?

EDIT:

Though there are different views or multiple ways for designing data sync in an android app, want to understand few things:

  1. Storage options
    a. Storing in native sqlite or NoSQL databases like Realm, CouchDB Lite ?

  2. Sync options
    a. For syncing, do i need to have sqlite db structure to be same as server db ?
    b. Can Realm be combined with Sync adapter or does Realm has any other options for syncing ?

  3. Database design
    a. Since each product item has further details to display upon clicking them, product details need to be fetched with another API call or all those details to be included in initial API call? what is the design approach to follow ?

  • Have a look at this related question. Everything you need is there. Please read all the answers: http://stackoverflow.com/questions/10829371/sync-data-between-android-app-and-webserver?rq=1 – narko Nov 02 '15 at 11:47

3 Answers3

2

Since the data is large and we need to have offline access to data through app, syncing data becomes very important. I am still learning these things.

So my thought on this problem is to use Google Cloud Messaging as server will be sending signal (if there is change in server database) to all the client apps to update its local database.

First of all when the application Runs at first, all the products will be loaded and saved to the app or you can show them as you like.

So when there is a update or new product entry, server will send push message to all the clients telling them that new product is added to server ( you can sent 4KB max data to client and in that case you should sent your product id )

then you can fetch data from server ( by product id) and update client local database.

https://developers.google.com/cloud-messaging/

For Database see this link :-

Should I use sqlite?

Community
  • 1
  • 1
Jamil
  • 5,457
  • 4
  • 26
  • 29
  • Thanks Jamil. Yes for informing clients about new data available at server, GCM is the approprate way. But, can you help me choose local db storage options among sqlite, realm and couchbase lite ? – Vinay Kashyap T S Nov 02 '15 at 07:53
  • I prefer SQLite .See my updated Answer. you can find facts, advantages and disadvantages of SQLite. – Jamil Nov 02 '15 at 08:22
1

You can go for Native sqlite option (sync using Sync adapter framework). As per your requirement i guess you would need the account login as well to list down the products so the Sync Adapater will take care of the Authentication as well. you can check http://developer.android.com/training/sync-adapters/creating-sync-adapter.html for more details on same.

so the Approach can be 1) when you start the app, check if an account has been created for your app and if not, create a new account and configure a periodic sync to start. 2) After sync it will be store the data inside the sqlite database. 3) Using cursorLoader you will fetch the data from the sqlite and display it on the UI.

This will allow the user to browse through the products even when there is no network connection.You can modify the query to fetch only specific amount of products and use recycle view to display the items on list.

One more important point which i feel is dont fetch the whole data from the server as you mentioned there can be 500-1000 and more products as there be always the case user might not browse through all the products and fetching such a large amount of data will sap more data bytes from the user data pack which obviously he/she never wants at the same time frequently making the network request will never allow the user device to go on StandBy mode and device battery will drained substantially as for every network call it make the device power up for around half a minute.

So now decide on some criteria on the number of products to be fetched on number of intervals which will take care of demerits mentioned above. That will definitely make user happy and your App will be much more efficient.

P.s while instantiating your Adapter pass 0 for the flags attribute so the Loader will be responsible for requiring your DB if the data has changed init.

Hope this helps you in deciding further steps.

Cheers.

Herin
  • 141
  • 5
0

Try out the firebase database, it provides android client through which you can sync the data very easily. For more details check out

https://www.firebase.com/docs/android/guide/offline-capabilities.html

jily
  • 344
  • 2
  • 11