1

Basically I want start a few threads which execute serially one after the another. I'm using Thread.join() for it. But the application kinds of hangs out and goes in ANR state. I want to know that putting an AsyncTask inside a loop will execute all the tasks serially one after the another or will they be executing parallelly???

for(String s : list)
{
    new asynctask(s).execute();
}
Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86
  • 2
    Consider using IntentService.You can add the tasks in Queue.Which will executed on non-UI Thread sequentially. – Vipul Jul 09 '12 at 06:21

1 Answers1

2

Basically I want start a few threads which execute serially one after the another.

The thing immediately comes to my mind after reading this statement is You should consider using IntentService Rather than Creating new Tasks each time.

Basically IntentService is

The IntentService receives a request via the Intent, which includes some information about the task to be completed. This task is then added to a queue,Then all tasks are completed sequentially and asynchronously.

The advantage of using IntentService would be

It will guarantee that the operation will have at least "service process" priority, regardless of what happens to the activity.It is highly recommended when you want to download multiple files sequentially.

Here you will find very good tutorial on how to implement IntentService.

http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/

Vipul
  • 27,808
  • 7
  • 60
  • 75