You can:
- Register your class responsible for executing AsyncTask as a listener in your AsyncTask.
- Embed a callback in your AsyncTask when the task completes at the end of doInBackground.
- Run the following AsyncTask when receiving 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) {
Your AsyncTask contains an 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 runnnable for 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(); } };
source share