Share the post "2 AsyncTask Does Not Run Asynchronously In Android"
Well, here’s the thing. The execute() method of AsyncTask were first introduced to execute serially on a single background thread.
Then it was changed to a pool of threads allowing multiple tasks to operate in parallel beginning with Android Donut OS.
With HoneyComb, tasks are executed on a single thread to avoid common application errors caused by parallel execution.
So if you want to run 2 or more tasks asynchronously, you use the method executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
If your app supports older versions prior to HoneyComb, you can do this kind of check:
|
1 2 3 4 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else task.execute(); |