Android two AsyncTasks serially or parallel execution? - The second is freezing but the result is ok(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 串行执行还是并行执行?- 第二个是冻结,但结果还可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android 两个 AsyncTask 串行执行还是并行执行?- 第二


基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01