调用从另一个AsyncTask的一个AsyncTask的 [英] Calling an AsyncTask from another AsyncTask

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

问题描述

在某一点上我的AsyncTask,部分验证已经完成后,我需要生成了另一个线程做一些其他工作。所以我想两个后台线程在这一点上,每一个做自己的事情(约2-3秒,以执行每个)。这样做是为了最大限度地提高双核处理器一样的Atrix的性能。

是可以接受再创建一个AsyncTask的&放大器;从第一个执行它?任何人都可以提出这样做​​的更好的办法?

谢谢!

编辑:我不知道什么publishProgress()的第二个任务,甚至会去做......因为它不是从活动开始

解决方案
  

是可以接受创建另一个   AsyncTask的&放大器;从第一执行它   一个?

是的,但只有在 onProgressUpdate() onPostExecute(),因为这些方法运行在UI线程上。因此,通过选择上面列出的两种方法之一启动第二的AsyncTask 在UI线程上。

  

我不知道什么publishProgress()   从第二个任务,甚至会做...   因为它不是从开始   活动?

这不完全一样的东西,因为你是从UI线程启动它。

At a certain point of my AsyncTask, after some validations have been done, I need to spawn off another thread to do some other work. So I'd like two background threads at this point, each doing it's own thing (approx 2-3 seconds to execute each). The idea is to maximize performance on dual core processors like Atrix.

Is it acceptable to create another asynctask & execute it from the first one? Can anyone suggest a better way of doing this?

Thanks!

EDIT: I'm wondering what publishProgress() from the second task would even do... since it was not started from an Activity?

解决方案

Is it acceptable to create another asynctask & execute it from the first one?

Yes, but only inside onProgressUpdate() or onPostExecute() since these methods runs on the UI thread. Therefore, start the second AsyncTask on the UI thread by choosing one of the two methods listed above.

I'm wondering what publishProgress() from the second task would even do... since it was not started from an Activity?

It does exactly the same thing, since you are starting it from the UI thread.

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

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