Android: execute several AsyncTask’s

I wanted to executed two separate AsyncTasks – one is for getting data from web page and another – to update UI.

I found that this is possible without any problems on Android < 3.0.

The article on StackOverflow helped me to resolve my problem with Android 4+ Running multiple AsyncTasks at the same time — not possible?

@TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11
void startMyTask(AsyncTask asyncTask) {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    else
        asyncTask.execute(params);
}

And here we go – two AsyncTasks are running simultaneously on any Android OS version.

Leave a Reply

%d bloggers like this: