多个异步任务不是在安卓4.1上运行是在、多个、任务

由网友(Lotus(忘忧))分享简介:在我的Andr​​oid应用我使用3个不同的异步任务。2任务在活动正在运行和第三的是在活动B.当我运行在OS的模拟器版本2.3的应用程序工作正常的应用程序。但是,当我试图在Android 4.0以上的版本只第一AsyncTask的运行。 In my android app i'm using 3 different...

在我的Andr​​oid应用我使用3个不同的异步任务。2任务在活动正在运行和第三的是在活动B.当我运行在OS的模拟器版本2.3的应用程序工作正常的应用程序。但是,当我试图在Android 4.0以上的版本只第一AsyncTask的运行。

In my android app i'm using 3 different async task. 2 tasks are running in Activity A and 3rd one is in Activity B. While i'm running the app in Emulator of OS version 2.3 application is working fine. But while i'm trying in Android 4.0 or higher version only first Asynctask is running.

有没有办法在4.0及更高版本上运行的所有3异步任务?

Is there any way to run all the 3 Async tasks in 4.0 and higher version?

推荐答案

您可以执行以下操作:

YourAsyncTaskClassObjectName.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

YourAsyncTaskClassObjectName.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

代替正常执行:

YourAsyncTaskClassObjectName.execute()

YourAsyncTaskClassObjectName.execute()

这实际工作对我的简单的非商业应用程序。现在,我已经2 asynctasks永远运​​行doInBackground方法(我而(真)内的每个)。

This actually worked for my simple non business app. Now, I've the doInBackground methods of two asynctasks running forever (i've while(true) inside each).

警告:我不是说这是最好的设计,但其实这工作

Caveat: I'm not saying this is the best design but this actually worked.

阅读全文

相关推荐

最新文章