Skip to content Skip to sidebar Skip to footer

Android App Which Works In Online And Offline Mode?

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

Solution 1:

  • 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

Solution 2:

Use SQLite database. Save data in database when there is no internet. Then sync data with server when internet comes back.

http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Solution 3:

You can use SQLite database in your android application. At offline you can save every thing in you local database and when application come with online then you can sync your local database with server database.

For create SQLite local database in android application you can check the following sample codes (sample projects) in github

https://bitbucket.org/kavi707/grocery_items_app/src

Cheers...

Solution 4:

Here you can not fetch data without internet. But it is possible to use old data. Once you are downloading data from internet store it into database. Here most people suggest SQLite database. My suggestion use anyone database (SQLite or SQLCipher) . After that before uploading your data just insert it into database and post from database. Because once network failure data will not be lost.

Broadcast Receiver:

This broadcast receiver is used to notify you the network changes. Once network is connected write your post code. Maybe here also possible to the network failure. But data still in database so it won't loss.

Post a Comment for "Android App Which Works In Online And Offline Mode?"