2

I am run two Async Tasks in the same block of code and the doInBackGround portions of the two tasks are running simultaneously, which is causing problems. According to the article linked below in android 1.5 Async Tasks were automatically qeued by order of execution, but this feature was removed for Android 1.6. All of the Async Task queing resources I've found advocate using threadPool but this is only available for Honey Comb. Any suggestions on the right way to handle this problem?

Article: parallel execution of AsyncTask

Community
  • 1
  • 1
Ben Pearce
  • 6,884
  • 18
  • 70
  • 127

1 Answers1

4

AsyncTask.get() will cause the calling thread block execution and wait for it finish, you can do something like this:

myAsyncTask1.execute();
myAsyncTask1.get();
myAsyncTask2.execute();

This will guarantee the 2nd AsyncTask is executed after 1st one finish, bear in mind that AsyncTask.get() block thread execution, so if you call this in UI thread,you will probably get ANR exception.

yorkw
  • 40,926
  • 10
  • 117
  • 130