我有同样的问题
Running multiple AsyncTasks at the same time — not possible?
除了我使用android 4.0与android:minSdkVersion =“14”.
除了我使用android 4.0与android:minSdkVersion =“14”.
我试过他的例子,并得到:
bar bar bar bar bar bar bar bar bar
编辑:
而不是使用:
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.