Anyone have any best idea to work Android application online as well as offline? Also, how can I manage server side data sync with the local database?

1

There are 1 best solutions below

2
On

Steps to take for a complete offline application:

1) Your UI always displays the data from the db and actively listens to any db changes.

2) Whenever user interacts with your application, you directly update the db and mark the relevant fields in your db to sync with your server. (Note that your UI gets updated instantly as it is listening to db changes)

3) Your network layer listens to marked field changes in your db and tries to sync with server.

4) When server side changes are successful, you unmark your db fields which are now synced successfully.

5) If you are implementing a down-sync (i.e: server has the updated data and wants the client to update accordingly), you can send a push notification to the device and make a network call to fetch the latest data depending upon the notification message.

For this to work smoothly, you will need a reactive database. Realm database is one such example that I have used.