1

I have an app that must save form inputs instead of send if there is no web connection.

And send them once the phone is connected.

I was wondering if there is already some code made to handle the feature.

Otherwise, the solution would be to save in sharedpreferences something like :

1_inputA
1_inputB
2_inputA
2_inputB

Do you have any other idea ?

Julien D
  • 1,259
  • 9
  • 22

1 Answers1

1

I think you can do it like this:

  1. Create the Service which will be run in background all the time.
  2. Create the ArrayList with Serealizable objects, every objects hold info about one request which you want to send.
  3. In Service create the the AlarmManager which will checks every N minutes/seconds if there is internet connection.
  4. After user enter data to input form, you also check is there is internet connection. If no, you just add new object to ArrayList and searelize (write to disk) the ArrayList.
  5. If there is a connection you desearelize (read from the disk ArrayList), add there your last input data and send it to server.
  6. Also every N time your AlarmManager check if there is interenet connection, it do the same thing as wrote in 5.
Alon Zilberman
  • 2,120
  • 1
  • 16
  • 16
  • Thanks for your solution, very interesting, ArrayList Serializable. Is this good to save ArrayList like this http://stackoverflow.com/questions/4118751/how-do-i-serialize-an-object-and-save-it-to-a-file-in-android ? – Julien D May 14 '14 at 12:48
  • Yes, it is good way to save it, just don't forget to 'implement serializable' in object which you will store in ArrayList – Alon Zilberman May 14 '14 at 13:01