Android的2 AsyncTasks串行或并行执行? - 二是冻结,但结果是确定 [英] Android two AsyncTasks serially or parallel execution? - The second is freezing but the result is ok

查看:130
本文介绍了Android的2 AsyncTasks串行或并行执行? - 二是冻结,但结果是确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑在我的Andr​​oid适用的两个AsyncTask的任务,这是来自同一类,但有不同的参数。例如:

 新myAsynckTask(A,B,C).execute();
新myAssyncTask(A,D,E).execute();
 

难道他们在并行或串行顺序执行?请问这是因为第一次启动时,显示执行的进展情况和结束的时候我看到了第二个,需要更多的时间来完成,但我看不到进度(我能看到矩形,但进度条没有显示20%..等等)。这就像冻结,但结果是确定的。

我想要做的是在串行顺序运行它们,并能够看到他们两个的进度。 我跑在Android果冻豆4.2.2 API等级17

应用程序
解决方案
  

难道他们在并行或串行顺序执行?

如果你的机器人:targetSdkVersion 是13或更高,而你是Android 3.2或更高版本的设备上运行,它们将被串行执行

如果您是在Android 1.5上运行,它们将被串行执行。

,否则,它们将被并行执行。

您可以通过替换选择到并行执行执行() executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)

有关更多信息,请参阅的AsyncTask 的JavaDoc 。

I run two AsyncTask tasks in my Android application which are from the same class but with different parameters. For example:

new myAsynckTask(a,b,c).execute();
new myAssyncTask(a,d,e).execute();

Do they execute in parallel or in a serial order? I ask this because when the first one starts, shows the progress of execution and when finishes I see the second one which needs more time to finish but I can't see the progress(I'm able to see the rectangle but the progress bar is not showing 20%..and so on). It's like freezing but the result is ok.

What I want to do is to run them in serial order and be able to see the progress in the two of them. I run the app on Android Jelly Bean 4.2.2 API Level 17

解决方案

Do they execute in parallel or in a serial order?

If your android:targetSdkVersion is 13 or higher, and you are running on an Android 3.2 or higher device, they will be executed serially.

If you are running on Android 1.5, they will be executed serially.

Otherwise, they will be executed in parallel.

You can opt into parallel execution by replacing execute() with executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR).

For more, see the "Order of Execution" section of the AsyncTask JavaDocs.

这篇关于Android的2 AsyncTasks串行或并行执行? - 二是冻结,但结果是确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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