Android 4.0 asynctask同时不可能

前端之家收集整理的这篇文章主要介绍了Android 4.0 asynctask同时不可能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有同样的问题 Running multiple AsyncTasks at the same time — not possible?
除了我使用android 4.0与android:minSdkVersion =“14”.

我试过他的例子,并得到:

bar bar bar
bar bar bar
bar bar bar

编辑:

我找到了解决方here

而不是使用:

task.execute();

使用 :

task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,null);

解决方法

听起来这样的解释(来自 documentation):

When first introduced,AsyncTasks were executed serially on a single background thread. Starting with DONUT,this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting with HONEYCOMB,tasks are executed on a single thread to avoid common application errors caused by parallel execution.

If you truly want parallel execution,you can invoke executeOnExecutor(java.util.concurrent.Executor,Object[]) with THREAD_POOL_EXECUTOR.

原文链接:https://www.f2er.com/android/316152.html

猜你在找的Android相关文章