Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app which works in online and offline mode? [closed]

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.

like image 564
zohaib Avatar asked Aug 27 '14 05:08

zohaib


3 Answers

  • 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
like image 125
mesh Avatar answered Oct 20 '22 11:10

mesh


What you are asking is actually incredibly complicated.

I have spent a good year of my own time trying to solve this problem and have published my work in the SyncIt project which is at http://forbesmyester.github.io/SyncIt/ .

There is:

  • A local version control system https://github.com/forbesmyester/SyncIt
  • A server component https://github.com/forbesmyester/syncit-server
  • A connection monitoring component https://github.com/forbesmyester/SyncItControl
  • And a basic bootstrap project that will give you a super basic to do list like project which you who be able to use as a basis for your project... https://github.com/forbesmyester/SyncItBootstrap

I suggest that you start reading about the local version control component and then move onto the connection monitoring component.

like image 35
Forbesmyester Avatar answered Oct 20 '22 10:10

Forbesmyester


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/

like image 34
fida1989 Avatar answered Oct 20 '22 09:10

fida1989