1

I'm developing a app that requires sync with the server app every 5 minutes... Which is the best way to accomplish that? I'm using a ThreadPoolExecutor (java way...) but I'm not very happy with that... and I want to know what other solutions can you provide me....

Thanks!

Vinay
  • 2,395
  • 3
  • 30
  • 35
Javier Manzano
  • 4,761
  • 16
  • 56
  • 86

3 Answers3

3

Either you can use Thread, AsyncTask with time interval of 5 minutes, or just use a background service which execute web-service at every 5 minutes continuously.

Also Use AlarmManager to set up your schedule and an IntentService to do the actual work. The IntentService automatically gives you your background thread for your network I/O, and it automatically shuts down the service when the work is complete.

user370305
  • 108,599
  • 23
  • 164
  • 151
1

Try using AlarmManager to wake up your app (service or whatever) every 5 minutes to perform the operation.

Some examples:

  1. It wakes CPU every 10 minutes until the phone turns off: Alarm Manager Example

  2. Using AlarmManager to Schedule Activities on Android: http://justcallmebrian.com/?p=129

Community
  • 1
  • 1
Soham
  • 4,940
  • 3
  • 31
  • 48
1

I favour alarm manager / broadcast receiver solution with non-wakeup alarms. Updating information from webservice seldom makes sense for slleping phones ( as there is no user present to react or notice changes ) - thus you can save traffic and power

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35