AsyncTask execute() or executeOnExecutor()?

.execute() – this function schedules the task on a queue for a single background thread. Means that if you are calling two AsyncTasks and using .execute() method to call them, they will execute in a queue(first then second).

.executeOnExecutor() – If you want parallel execution of both AsyncTasks, you can use this method for execution of AsyncTask. Means both asyncTasks will execute simultaneously.

In simple words: .execute() method creates a single thread for execution of asyncTasks, and .executeOnExecuter() method creates separate thread for each ayncTask.

.execute executes tasks by default in serial order.

EDITED:
If you want to use executeOnExecutor() you can use this code:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
     task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
 else
     task.execute();

Before HONEYCOMB execute() method run AsynkTask in parallel.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)