title: How can I loop my AsyncTask to download a data blob in a loop?
body: <p>I'm running <code>httpsCommand</code> (shown below, via <code>clientTask()</code> from <em>MainActivity</em>) and downloading about 1KB of data from a webserver. I plan to update a ListView in <em>MainActivity</em> (I think that's possible, but I recall it being a bit annoying last time I did it) with the downloaded data inside <code>myListAllDoneListener()</code>.  I'd like to run this in a loop every 5 minutes to check for new data.</p>
  
  <p>I've tried running <code>new myCLientTask().execute()...</code> inside a while loop (using <code>Thread.sleep</code> and try/catch) but it only seemed to run one loop and crashed after 15 seconds or so. Found a <a href="https://stackoverflow.com/questions/17059217/managing-background-download-android">similar question</a> but it's not quite answered. How can I background this data download?</p>
  
  <pre><code>// ** MainActivity.java **
  public class MainActivity extends AppCompatActivity
  {
     ...
     @Override
     protected void onCreate(Bundle savedInstanceState)
     {    
      new clientTask(getApplicationContext(), myListAllDoneListener, ...);
          ...
  
     private AsyncTaskCompleteListener myListAllDoneListener = new AsyncTaskCompleteListener()
     {
        @Override
        public void onComplete(ArrayList&lt;String&gt; data, String msg, int statuscode)
        {
          // update listview with new data
          ...
  
  
  //** clientTask.java **
  public class clientTask extends Activity
  { 
    ArrayList&lt;String&gt; mData;
    ...
  
    public clientTask (Context ctx, AsyncTaskCompleteListener ... String cmd, ...)
    {
      ...
      new myClientTask().execute();
      ...
  
  
    private class myClientTask extends AsyncTask&lt;Object, Object, Object&gt;
    {
    ...
  
    protected Object doInBackground (Object... params)
    {
       mData = httpsCommand (mCmd);
       ...
  </code></pre>