Question: I am facing an issue regarding the order of exection of AsyncTasks.

My question is :

Assuming I have 2 implementations of AsyncTask : **MyAsyncTask1** and **MyAsyncTask2**

That are called in the following manner :

```java
new MyAsyncTask1 ().execute ();
new MyAsyncTask2 ().execute ();

```

Is it garanteed that **MyAsyncTask1** is executed before **MyAsyncTask2** ?
One thing for sure, they are not executed in parallel since the default executor is used, which is **SERIAL\_EXECUTOR**.
The problem lies in the order of execution : which will be executed first ??

If the order of execution is not determined, how can I enforce an order of execution for the AsyncTasks ??

What I need is to have **MyAsyncTask1** executed before **MyAsyncTask2**, which is not always the case, eventhough I am calling execute for **MyAsyncTask1** before **MyAsyncTask2**.

What I actually have is a custom activity :

```
public abstract class CustomActivity extends Activity {

    @Override
    protected void onCreate ( Bundle savedInstanceState ) {
        super.onCreate ( savedInstanceState );
        new MyAsyncTask2 ().execute ();
    }
}

```

And another activity that inherits from the custom activity :

```
public class MainActivity extends CustomActivity {

    @Override
    protected void onCreate ( Bundle savedInstanceState ) {
        new MyAsyncTask1 ().execute ();
        super.onCreate ( savedInstanceState );
    }
}

```

So if I use the **MainActivity**, **MyAsyncTask1** should be executed before **MyAsyncTask2**, at least that is the behavior I need.

Answer: 
The only way to ensure that two threads (that's what AsyncTasks basically are) are executed in the order you want, is to start the second thread when the first one finishes.

In your case, to keep implementation abstracted and not have to actually call AsyncTask2 in the `onPostExecute` of AsyncTask1 (the way Anup and Sanket suggested, which is also fine if you want to mix them), make AsyncTask1 call `super.executeAsyncTask2()`, where `executeAsyncTask2()` is a method in your CustomActivity which starts the second AsyncTask
Call your second Async task at the end of the first Aysnc task (i.e at the end of the `onPostExecute()` method of your first async task)

```
//first async task's onPostExecute method

onPostExecute()
{
//do your stuff and call second async task

new MyAsyncTask2 ().execute ();

}

```

This will guarantee execution of the second task after the first one in a simple and elegant fashion.