Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 views
in Technique[技术] by (71.8m points)

how to send data to server from android when no internet is available

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...