我有同样的问题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.
关于Android 4.0 asynctask 同时不可能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8718402/