You could:
- Register your class responsible of the AsyncTask execution as listener in your AsyncTask.
- Implement a callback in your AsyncTask when the task is finished at the end of the doInBackground method.
- Execute the next AsyncTask when you receive the callback.
Example:
Your listener interface:
public interface IProgress {
public void onProgressUpdate(final boolean isFinished);
}
Your activity implements IProgress:
public class MyActivity implements IProgress {
public void onProgressUpdate(final boolean isFinished) {
if (isFinished) {
// delayed execution
myHandler.postDelayed(new MyRunnable(MyActivity.this), 30000);
}
}
Your AsyncTask contains a IProgress instance and you call onProgressUpdate at the end of doInBackground or in onPostExecute:
...
private final IProgress progressListener;
public MyAsyncTask( final IProgress progressListener) {
super();
this.progressListener = progressListener;
}
...
@Override
protected void onPostExecute(final int result) {
progressListener.onProgressUpdate(true);
super.onPostExecute(result);
}
Create a runnnable for the postDelayed:
protected class MyRunnable implements Runnable {
private final IProgress progressListener;
public MyRunnable(final IProgress progressListener) {
super();
this.progressListener= progressListener;
}
public void run() {
new MyAsyncTask(progressListener).execute();
}
};