execute AsyncTask Serially - Android android.os

Android examples for android.os:AsyncTask

Description

execute AsyncTask Serially

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 executeSerially(
            T task) {/*from  w w  w.jav a2  s .co  m*/
        executeSerially(task, (Params[]) null);
    }

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

    }
}

Related Tutorials