0

I am new to mobile development and still have much to learn. I have written an Android application that collects user data in SQLite database locally. I would like this data to be uploaded separately to users actions, which means:

  • When the user is using the application, all of the data is stored locally,
  • If the user has internet connection, data can be uploaded immediately to data server (no problem about the server side, php scripts are already written for data insertion),
  • If the user has no internet connection, the application will wait for any connection and then upload the data.

I would like to know, what is the best approach to do this - is it any kind of service running in the background, or anything else? I have read about services only in tutorials, so I don't know exactly how to deal with them and if I should even bother writing them, to achieve what I have mentioned above?

Regards.

Kuba M
  • 139
  • 12

1 Answers1

1

Actually services are not so necessary for that (Example: if you have only one activity). Service helps you keep off thread work apart of activity lifecycle. Ok. Now, decision of your problem step-by-step:

  1. You need to create off thread work (AsyncTask, Thread etc.), which tries to send you data to server
  2. If it fails you can use "connection changed" listener of just schedule your next try with Handler.postDelayed
  3. Service only helps you to keep control of that off thread work from different activities if you need that
Romadro
  • 626
  • 4
  • 10