Android - Async Task behavior in 2.3.3 and 4.0 OS

前端 未结 3 1115
忘了有多久
忘了有多久 2020-12-10 18:26

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) an

3条回答
  •  旧巷少年郎
    2020-12-10 18:54

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

    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 - 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.

提交回复
热议问题