A little help with trying to time an async task
<p>Situation: I would like to pull a network resource (a file), display it for 30 seconds, then load the next file. While displaying the initial file for 30 seconds, I'd like to preload the next file.</p>

<p>Question: Should I be using concurrent threads with a lock (like a linked blocking queue?) or a handler? Or something I'm missing?</p>

<p>Currently I have the onCreate call an asynctask that has a for loop which iterates through an array of paths for the files one at a time, which then calls the next asynctask (inside the for loop) which downloads the file from that path and then in the onPostExecute assigns the file to the UI view. </p>

<p>This works but I am unable to setup timing where the first file loads in the UI view then 30 seconds later the next file loads in the UI view and so on... Right now it loads the files fine but the 1st may take 40 seconds to display and the 2nd 25 seconds and the 3rd 60. </p>

<p>(FYI, the files are uniform size and only take 5~15 sec to load)</p>

<p>Here's a general example (non compile-able):</p>

<p>onCreate(){
new firstAsynchTask().execute(filePaths[]);
}</p>

<pre><code>private class firstAsynchTask extends AsyncTask&lt;String[], Void, Void&gt; {
    protected Void doInBackground(String[]... x) {
        try {
            for(int i = 0; x[0] != null &amp;&amp; i &lt; x.length; i++)
            {
                long startT = System.currentTimeMillis();
                if(x[0][i].isFile())
                {
                    SmbFile g = new SmbFile(x[0][i].getPath());
                    new secondAsynchTask().execute(g);
                    long TimeNow = (System.currentTimeMillis() - 30000);
                    if(startT &gt; TimeNow)
                    {
                      try {
                           Thread.sleep(startT - TimeNow);
                       }  catch (IOException e) {
                                      // TODO Auto-generated catch block
                                       e.printStackTrace();}
                    }
                }
                if(i == x.length - 1)
                {
                    i = 0;
                }

            }
            return null;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            return null;
        }   
    }

private class SecondAsyncTask extends AsyncTask&lt;File, Integer, Drawable&gt; {
    protected File doInBackground(File... x) {

        SomeType FileTemp = new File();
        try {
            long startT = System.currentTimeMillis();
            FileTemp = (get streamed file);
            long TimeNow = (System.currentTimeMillis() - 30000);
            if(startT &gt; TimeNow)
            {
               Thread.sleep(startT - TimeNow);
               return FileTemp;
            }
            else
            {
                return FileTemp;
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }

    }

   protected void onPostExecute(File result) {
        if(result != null)
        {
        FileView centerFile = (FileView) findViewById(R.id.FileView1);
        centerFile.setFile(result);
        }
    }
}
</code></pre>
