AsyncTask executor, if the phone is below HoneyComb it's use a single executor above HoneyComb parallel executor. - Android android.os

Android examples for android.os:AsyncTask

Description

AsyncTask executor, if the phone is below HoneyComb it's use a single executor above HoneyComb parallel executor.

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.os.Build;

public class Main {
    /**/*from w  w  w  . j  a va  2  s.c  om*/
     * AsyncTask executor, if the phone is below HoneyComb it's use a single executor
     * above HoneyComb parallel executor.
     * @param task
     * @param <P>
     * @param <T>
     */
    public static <P, T extends AsyncTask<P, ?, ?>> void execute(T task) {
        execute(task, (P[]) null);
    }

    @SuppressLint("NewApi")
    public static <P, T extends AsyncTask<P, ?, ?>> void execute(T task,
            P... params) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
        } else {
            task.execute(params);
        }
    }
}

Related Tutorials