2

I've made a form app that send data to my mysql server. All is good but I have a question: what should I use if my app doesn't have internet..the user enters the data and is submitted if I have internet but what if for 5 or 10 minutes i don't have internet acces and the user still sends data. Do I lose that data or is there a way to save the data and when the internet is activated again all the data saved is transmited to my mysql server...??

I've heard about JSON Parser but i don't know exactly how it works...

Rares Biris
  • 195
  • 1
  • 3
  • 18
  • if internet is not available , then store it in sharedpreference( good for Small amount of data ) or DB ( for huge amount of data ) and if you got internet connection then send that stored data – Vaishali Sutariya Oct 14 '14 at 11:48
  • save data in your local database and sync whenever internet connection available.... – Rohit Goswami Oct 14 '14 at 11:49

1 Answers1

21

Set up a BroadcastReceiver in your android application

When your user submits some data and press submit then check for the internet connection of the device.If internet is not available then store the data in the local database or shared preferences(if data is small). Now when internet will be available,your broadcast receiver will be called and will check the data in the local database.If present ,it will have to send that data as you used to do already.


  1. For checking the internet connection : How to check internet access on Android? InetAddress never times out
  2. For creating Broadcast Reciever for checking availability of network : Broadcast receiver for checking internet connection in android app
  3. For dealing with database : Android SQLite Example
  4. If you wish to use sharedPreferences : How to use SharedPreferences in Android to store, fetch and edit values
  5. For sending data to server : Sending POST data in Android

nobalG
  • 4,798
  • 3
  • 29
  • 63
  • 3
    since Android N, Google recommends to use JobScheduler, instead of Broadcast to do background tasks (by the way `android.net.conn.CONNECTIVITY_CHANGE` is now deprecated) – murt Sep 21 '17 at 09:31