gpt4 book ai didi

Android 4.0 asynctask 同时不可能

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:19 24 4
gpt4 key购买 nike

我有同样的问题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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com