Android app which works in online and offline mode?

zohaib picture zohaib · Aug 27, 2014 · Viewed 16.6k times · Source

I'm new to Android and and made an application which fetched and post data to server and works fine in online mode. But I want to make it works in offline mode also, when there is no internet connection or network failure. It should also make changes (updates) to the server database when net is available. I have done lots of R & D but didn't get the useful info.

Please someone guide me with some useful steps, sample code (if possible) or any link to make app in offline mode.

Answer

AK42 picture AK42 · Aug 27, 2014
  • You need to define two modes of your app online and offline
  • Monitor Network Connectivity events in your app to determine offline/online mode, You need to write BroadcastReciever for this.
  • In online mode Connect to your server and exchange whatever data that you need to do at that point.
  • Meanwhile in offline mode store the data persistently if needed