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 串行执行还是并行执行?- 第二


- C++ 和 Java 进程之间的共享内存 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01