execute AsyncTask Parallel - Android android.os

Android examples for android.os:AsyncTask

Description

execute AsyncTask Parallel

Demo Code


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

public class Main {
    public static <Params, T extends AsyncTask<Params, ?, ?>> void executeParallel(
            T task) {//  w w w . j a  v  a 2s. com
        executeParallel(task, (Params[]) null);
    }

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

Related Tutorials