Android的 - 在2.3.3和4.0操作系统的异步任务的行为 [英] Android - Async Task behavior in 2.3.3 and 4.0 OS

查看:153
本文介绍了Android的 - 在2.3.3和4.0操作系统的异步任务的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试,我们有一个列表视图中检索了网络在图像列表中的应用程序。当我运行在Android设备2.3.3(WIFI速度512 Kbps)的应用程序,并检查DDMS(线程浏览器),线程的数量不断从25提高到50但是,当我测试设备的4.0(WIFI速度相同的应用程序5 MBPS),线程数没有增加。

I am testing an application where we have a list view with list of images retrieved over network. When i run the application on android device 2.3.3 (WIFI speed 512 KBPS) and check the DDMS (Thread Viewer), the number of threads keeps increasing till 50 from 25. But when i test the same application on device 4.0 (WIFI speed 5 MBPS), number of threads did not increase.

谁能帮助我了解为什么发生这种情况?它是由于Android操作系统的差异,或任何其他原因?

Can anyone help me understand why this is happening ? Is it due to android OS difference or any other reason ?

在此先感谢。

推荐答案

您期运用的AsyncTask 。安卓3.0后,默认行为的AsyncTask 在一个单独的线程使用SERIAL_EXECUTOR执行。

Are you useing AsyncTask. After Android 3.0, the default behavior of AsyncTask is execute in a single thread using SERIAL_EXECUTOR.

如果你想的AsyncTask 同时在任何系统上运行的版本,你可以使用这个code。

If you want AsyncTask run concurrently on any system version, you may use this code.

AsyncTask task = new YourTask();
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
    task.execute(params);
} else {
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}

pre OS 1.6 - 多个异步任务被按顺序执行。 OS 1.6至OS 2.3 - 异步任务并行运行。 从3.0 - 再次,异步任务被按顺序执行。

Pre OS 1.6 - Multiple Async Tasks gets executed in sequence. OS 1.6 till OS 2.3 - Async Tasks run in parallel. From 3.0 - Again, Async Tasks gets executed in sequence.

这篇关于Android的 - 在2.3.3和4.0操作系统的异步任务的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆