I am getting data from the server using AsyncTask
. I need to update the data periodically.
Whats the best way to do it?
I am getting data from the server using AsyncTask
. I need to update the data periodically.
Whats the best way to do it?
You can do it either on your onProgressUpdate()
or on onPostExecute()
based on your requirement.
onProgressUpdate(Progress...)
, invoked on the UI thread after a call to publishProgress(Progress...). The timing of the execution is undefined. This method is used to display any form of progress in the user interface while the background computation is still executing. For instance, it can be used to animate a progress bar or show logs in a text field.
onPostExecute(Result)
, invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.
http://developer.android.com/intl/de/reference/android/os/AsyncTask.html
Set an alarm with AlarmManager and call your AsyncTask
in your AlarmReceiver
class.
Hi,
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://developer.android.com/resources/articles/timed-ui-updates.html