Android: Async-task loaders

Android: Async-task loaders  #angularjs #reactjs

  • I’d use a timer for updating you data every 5 minutes.
  • I am not able to figure out how to periodically call the loader every 5 minutes to update the content.
  • While using loaders, we need to use restartLoader instead of initLoader if we need to periodically update the loader with new data.
  • I read that rotating screens would restart the activity and loaders are better than asynctasks.
  • My app needs to periodically fetch data from the web and update itself every 5 minutes.

My app needs to periodically fetch data from the web and update itself every 5 minutes. For the same, I was using Asynctask to fetch the content and process it in the background thread before sending it to the UI thread. Recently, I came to know about Asynctask Loaders and its benefits. However, I am not able to figure out how to periodically call the loader every 5 minutes to update the content.

@ng_real_ninja: Android: Async-task loaders #angularjs #reactjs

My app needs to periodically fetch data from the web and update itself every 5 minutes. For the same, I was using Asynctask to fetch the content and process it in the background thread before sending it to the UI thread. Recently, I came to know about Asynctask Loaders and its benefits. However, I am not able to figure out how to periodically call the loader every 5 minutes to update the content.

(Please note earlier I was using Timer to call task.execute(). I need to finally update my listview if there is any new content.)

In your activity, declare :

of your activity to reuse it afterward, use:

If you want to remove the service, use:

I figured it out finally.

While using loaders, we need to use restartLoader instead of initLoader if we need to periodically update the loader with new data. RestartLoader kills the previous loader and establishes a new one, while initLoader ignores the creation of a new loader if there already exists a loader with that id.

Android: Async-task loaders

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.