AsyncTask的一个循环内 [英] AsyncTask inside a loop

查看:131
本文介绍了AsyncTask的一个循环内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想开始执行该串行一前一后另一个线程数。我使用的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 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/

这篇关于AsyncTask的一个循环内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆