2

I need to upload data to the server repeatedly (say after every 10 minutes). The application will check in the local SQLite DB if there's any unsynced data and will upload it.

If I call an AsyncTask from a Handler repeatedly, will it work even when the app is paused (user navigates to another application)?

How can a Service be used to do this (as service can be run in the background)? Should I use Service or IntentService?

Abdul Fatir
  • 6,159
  • 5
  • 31
  • 58

2 Answers2

4

An AsyncTask can run after the calling app is destroyed, however, if it calls onPostExecute() it will crash the app if this method updates the UI. Handlers will also continue to run. However, the JVM process may be killed off at any time. AsyncTask is only supposed to be used for short tasks lasting a few seconds.

A Service is not married to an activity and can outlive it should the app be destroyed. This is where you should be updating your server.

A good tutorial: http://www.vogella.com/tutorials/AndroidServices/article.html

Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
0

If I call an AsyncTask from a Handler repeatedly, will it work even when the app is paused (user navigates to another application)?

When Android kills an app, can a function be stopped halfway?

"AsyncTask may continue running but may or may not to be fully functional"

How can a Service be used to do this (as service can be run in the background)? Should I use Service or IntentService?

I guess it is better to use service to do this. (i am not so sure anyway)

What is the difference between an IntentService and a Service?

Community
  • 1
  • 1
Chris Yu
  • 39
  • 2