Reputation: 2325
In my android app i'm using 3 different async task. 2 tasks are running in Activity A and 3rd one is in Activity B. While i'm running the app in Emulator of OS version 2.3 application is working fine. But while i'm trying in Android 4.0 or higher version only first Asynctask is running.
Is there any way to run all the 3 Async tasks in 4.0 and higher version?
Upvotes: 1
Views: 3317
Reputation: 361
You can do the following:
YourAsyncTaskClassObjectName.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
instead of the normal execute:
YourAsyncTaskClassObjectName.execute()
This actually worked for my simple non business app. Now, I've the doInBackground methods of two asynctasks running forever (i've while(true) inside each).
Caveat: I'm not saying this is the best design but this actually worked.
Upvotes: 5
Reputation: 2576
It's the correct behavior. AsyncTask since Android 4.0 , performes consistently.
Upvotes: 0
Reputation: 6721
With Android 4.0, AsyncTask have ben granted only one background thread of execution i.e. only one will run at a time. This was the same behaviour in FroYo, but was lifted in Gingerbread. hence then you could run multiple AsyncTasks. So the best way to proceed is to serialize your AsyncTasks. Parallelizing will lead to unpredicatable results.
Upvotes: 4
Reputation: 855
Hi you have to write your own executors. Please follow the post
execute the async task in serial order in android4.0
Upvotes: 1