I want to execute an asynctask after finishing the first task. But when printing the status the of the first task it always shows RUNNING.If execute both tasks parallel only smaller task will be executed. I am running both in activity oncreate method.Any idea?
here is my code sample
public class test extends Activity
{
ExecuteTask1 task1;
ExecuteTask2 task2;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
task1 = new ExecuteTask1();
task1.execute(token);
System.out.println(task1.getStatus());
if(task1.getStatus() ==AsyncTask.Status.FINISHED)
{
task2 = new ExecuteTask2();
task2.execute(token);
}
}
}
In your code right now, you aren’t giving task1 time to finish. Start task2 from the
onPostExecutemethod of task1. (You’ll have to modify the code in class ExecuteTask1 for this to work.)Alternatively, have task1 call back to your activity (or post a message to it or something) in
onPostExecuteso your activity can then start task2.