-3

I have a problem that I cant understand it at all!. I have an Asynctask that connects to a web service and download some data.

But when I do this my other Asynctasks waits to this Asynctask to finish his work evenAsynctasksin otherActivities`!!. But I can't understand this.

How I can avoid this?. I was thinking that Asynctasks can run simultaneously but now it doesn't!. What is the problem? It seems REST and downloading stream data blocks the entire app.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
Fcoder
  • 9,066
  • 17
  • 63
  • 100
  • You are going to have to show us some code. It is quite possible to run two or more async tasks simultaneously. – Dale Wilson Sep 23 '13 at 18:55
  • http://developer.android.com/reference/android/os/AsyncTask.html - just read the documentation :) – 323go Sep 23 '13 at 19:05

2 Answers2

5

If you're running on Android 3.0 or later, and you're using the default implementation of AsyncTask (i.e. the one from the framework), it'll only execute a single task at a time. It is, however, possible to get parallel execution. See below.

From the documentation of AsyncTask

Order of execution

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.

Community
  • 1
  • 1
Michell Bak
  • 13,182
  • 11
  • 64
  • 121
2

Use a executoOnExecutor

TheTask task = new TheTask();
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); 

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

Michell Bak
  • 13,182
  • 11
  • 64
  • 121
Raghunandan
  • 132,755
  • 26
  • 225
  • 256