Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to periodically executing AsyncTasks in Android

Tags:

java

android

I am getting data from the server using AsyncTask. I need to update the data periodically.

Whats the best way to do it?

like image 700
Kunal P.Bharati Avatar asked Sep 01 '10 11:09

Kunal P.Bharati


2 Answers

You could use Timer class to schedule periodic task using TimerTask instead of AsyncTask

See :

http://developer.android.com/reference/java/util/Timer.html

http://developer.android.com/reference/java/util/TimerTask.html

And to update your UI you should follow this good tutorial :

http://android-developers.blogspot.com/2007/11/stitch-in-time.html

like image 65
Mathieu Avatar answered Nov 09 '22 02:11

Mathieu


Set an alarm with AlarmManager and call your AsyncTask in your AlarmReceiver class.

like image 38
Macarse Avatar answered Nov 09 '22 02:11

Macarse