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

5

7

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.

Zooid answered 27/8, 2014 at 5:20 Comment(0)
T
9
  • 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
Tilley answered 27/8, 2014 at 5:53 Comment(1)
where i have to make changes, can you send some sample codes or any useful linkZooid
N
5

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:

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

Northey answered 27/8, 2014 at 5:20 Comment(0)
F
3

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/

Fagen answered 27/8, 2014 at 5:26 Comment(3)
the link is just about how to create db, nothing about app works in online and offline modeZooid
You will database to save data in online mode and fetch data in offline mode.Fagen
@Fagen Easy to say, but how to implement? I was reading about ContentProviders, Cursors, Services, but it is not totally clear for me. Can you suggest some specific tutorial?Freedwoman
G
2

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...

Garrard answered 27/8, 2014 at 5:29 Comment(1)
this app is static, and nothing define for online or offline modes in any activity code.Zooid
M
1

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.

Manicure answered 27/8, 2014 at 5:49 Comment(1)
where i have to make changes, can you send me some sample codes or nay useful linkZooid

© 2022 - 2024 — McMap. All rights reserved.