title: Looping AsyncTask
body: <p>I have custom <code>AsyncTask</code> (ListDownloadTask) that download data and updates UI. I want to make it forever while activity opened. So after AsyncTask did the work it must be scheduled. There are delays between attempts. </p>
  
  <p>I tried to use timer but the problem is <code>new ListDownloadTask().execute();</code> must be invoked from UI thread. </p>
  
  <p>Now i have timer that generates message for <code>Handler</code>. That seems ugly to me. What is best practice?</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
  // ...
      new ListDownloadTask().execute();
  }
  
  private static final long DOWNLOAD_UPDATES_DELAY = 5 * 1000;
  private final Timer mUpdatesDownloaderTimer = new Timer(true);
  
  Handler mDownloadTrigger = new Handler(new Handler.Callback() {
      public boolean handleMessage(Message message) {
          new ListDownloadTask().execute();
          return true;
      }
  });
  
  private void scheduleUpdatesDownload() {
      mUpdatesDownloaderTimer.schedule(new TimerTask() {
          @Override
          public void run() {
              mDownloadTrigger.sendEmptyMessage(0);
          }
      }, DOWNLOAD_UPDATES_DELAY);
  }
  
  private class ListDownloadTask extends AsyncTask&lt;Long, String, Integer&gt; {
      @Override
      protected void onPostExecute(Integer result) {
          //...
          scheduleUpdatesDownload();
      }
  </code></pre>