AsyncTask的一个循环内 [英] AsyncTask inside a loop
问题描述
基本上我想开始执行该串行一前一后另一个线程数。我使用的Thread.join()
它。但是,应用程序种类挂出的,去的ANR状态。我想知道,把一个AsyncTask的一个循环内将执行串行所有的任务之一后,又或者他们会被执行平行???
的(一个String:名单)
{
新的AsyncTask(S).execute();
}
基本上我想开始执行其连续一个接一个线程数
另一个。
块引用>事情立刻浮现在我的脑海里读取这种说法是您应该考虑使用IntentService而不是创建新任务以后每次
基本上IntentService是
的IntentService接收经由意图,其中包括一个请求
要完成有关任务的一些信息。这个任务是再
添加到队列,那么所有的任务都完成
依次是异步的。
块引用>使用的优点
IntentService
是这将保证该操作将至少有服务过程优先,不管发生什么情况activity.It强烈建议当你想按顺序下载多个文件。
在这里你会找到如何实现非常好的教程
IntentService
。的http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/
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(); }
解决方案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 beIt 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/
这篇关于AsyncTask的一个循环内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!