不同PARAMS执行相同的AsyncTask多次 [英] Executing same asynctask multiple times with different params

查看:264
本文介绍了不同PARAMS执行相同的AsyncTask多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有关于如何并行运行同一AsyncTask的很多问题:我需要的是执行相同的AsyncTask的,但每个任务不同PARAMS

I know there are a lot of question regarding how to run the same asynctask in parallel: what i need is to execute the same asynctask but with different params per task.

我有:

MyTask taskOne = new MyTask();
MyTask taskOne = new MyTask();
taskOne.execute(UrlOne);
taskTwo.execute(UrlTwo);

MyTask不得不从urlone和url两种下载的网页。当两种颜色之一,我杀了另一个与取消(真)。但如何才能在我并行运行的线程?

MyTask have to download the page from the urlone and url two. When one of the two finishes, i kill the other one with cancel(true). But how can i run those thread in parallel?

如果我尝试这一点,当taskOne结束,它只是杀了taskTwo。

If i try this, when taskOne ends it just kill taskTwo.

谢谢大家的帮助。

推荐答案

您应该使用一些同步机制就像一个信号灯或的ConditionObject。

You should have used some synchronization mechanism like a semaphore or a conditionobject.

https://www.youtube.com/playlist?list=PLZ9NgFYEMxp4tbiFYip6tDNIEBRUDyPQK

这篇关于不同PARAMS执行相同的AsyncTask多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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