Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
933 views
in Technique[技术] by (71.8m points)

android - AsyncTask inside a loop

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();
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...