I run two AsyncTask tasks in my Android application which are from the same class but with different parameters. For example:
new myAsynckTask(a,b,c).execute
UPDATE: copied from Android Developers and initiated by Yazazzello
"This class was deprecated in API level 26.0.0-alpha1. Use AsyncTask directly."
You should use this for parallel execution:
AsyncTaskCompat.executeParallel(new AsyncTask<Param, Void, Data>() {
@Override
protected Data doInBackground(Param... params) {
return downloader.getData(params[0]);
}
@Override
protected void onPostExecute(Data response) {
processData(response);
}
}, param);
Do they execute in parallel or in a serial order?
If your android:targetSdkVersion
is 13 or higher, and you are running on an Android 3.2 or higher device, they will be executed serially.
If you are running on Android 1.5, they will be executed serially.
Otherwise, they will be executed in parallel.
You can opt into parallel execution by replacing execute()
with executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
.
For more, see the "Order of Execution" section of the AsyncTask JavaDocs.
The answer to your question is: it totally depends on what version of Android you're running this on, and is a huge problem I've faced in several applications.
You should check out this link if you want to see how to run them correctly