When first introduced, AsyncTasks
were executed serially on a single background thread. Starting with DONUT
, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting with HONEYCOMB
, tasks are executed on a single thread to avoid common application errors caused by parallel execution.
If you truly want parallel execution, you can invoke executeOnExecutor(java.util.concurrent.Executor, Object[])
with THREAD_POOL_EXECUTOR
.
SERIAL_EXECUTOR -> An Executor that executes tasks one at a time in serial order.
THREAD_POOL_EXECUTOR -> An Executor that can be used to execute tasks in parallel.
sample :
Task task = new Task();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, data);
else
task.execute(data);