Android 两个 AsyncTask 串行执行还是并行执行?- 第二个是冻结,但结果还可以 [英] Android two AsyncTasks serially or parallel execution? - The second is freezing but the result is ok

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

问题描述

我在我的 Android 应用程序中运行了两个 AsyncTask 任务,它们来自同一类但具有不同的参数.例如:

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();

它们是并行执行还是串行执行?我问这个是因为当第一个开始时,显示执行进度,完成时我看到第二个需要更多时间才能完成但我看不到进度(我可以看到矩形但进度条没有显示 20% ......等等).就像冷冻,但结果还可以.

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.

我想要做的是将它们按顺序运行,并且能够看到它们两个的进度.我在 Android Jelly Bean 4.2.2 API Level 17 上运行该应用

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?

如果您的 android:targetSdkVersion 是 13 或更高版本,并且您在 Android 3.2 或更高版本的设备上运行,它们将被串行执行.

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.

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

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

否则,它们将并行执行.

Otherwise, they will be executed in parallel.

您可以通过将 execute() 替换为 executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR) 来选择并行执行.

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

有关更多信息,请参阅AsyncTask 的执行顺序"部分JavaDocs.

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

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

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