Adeel Ahmad
Adeel Ahmad

Reputation: 1000

What is the Default Execution Manner of AsyncTasks in Android?

android Asynctask has been modified quite frequently between different API-levels. I'm developing an Application in which i've to upload images to FTP server. i want to do that in serialized order (images upload after one-another by one image upload per asyntask). I understand the SERIAL_EXECUTOR and THREAD_POOL_EXECUTOR stuff, but i just want some clarity about what is the default behavior of asynctask ( my min. target API is ICS 4.0 ). if i simply execute say 10 asyncs' in a loop, will they go to thread queue and execute one by one or they'll just go parallel ?

Upvotes: 0

Views: 56

Answers (2)

Artur Szymański
Artur Szymański

Reputation: 1648

You can't use one async task with loop inside doInBackground()? If you want to have control over them, you can invoke second async task in onPostExecute() of first.

Upvotes: 0

Larry Schiefer
Larry Schiefer

Reputation: 15775

Look in the AsyncTask documentation:

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.

So, with min target of 14, they will be serialized.

Upvotes: 3

Related Questions