-2

I have two asynctasks. One of them is updating the part of title bar every second. After I start other asynctask(which updates other screen element every second as well), first one still runs, but cannot update screen. I call UI stuff on onProgressUpdate() .No exception is thrown. All works fine in separate. Problems only when ocur concurent. I do not understand why. I do use API 8 (FROYO).

Thank You.

Balvonas
  • 179
  • 2
  • 11

1 Answers1

1

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.

For more information have a look at the link below.

http://developer.android.com/reference/android/os/AsyncTask.html

https://github.com/vitkhudenko/test_asynctask. A sample of asynctask to test and play with

As an alternative you can use RoboSpice. Can handle multiple spice requests. https://github.com/octo-online/robospice

Edit: Check the link below there is a good explanation regarding the topic.

Running multiple AsyncTasks at the same time -- not possible?

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

http://developer.android.com/reference/java/util/concurrent/Executor.html

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256