Executing same asynctask multiple times with different params

ぐ巨炮叔叔 提交于 2019-12-25 02:43:46

问题


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.

I have:

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

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?

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

Thanks all for help


回答1:


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

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



来源:https://stackoverflow.com/questions/22656332/executing-same-asynctask-multiple-times-with-different-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!