execute AsyncTask With Result String - Android android.os

Android examples for android.os:AsyncTask

Description

execute AsyncTask With Result String

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;

import android.os.AsyncTask;
import android.os.Build;

public class Main {
    @SuppressLint("NewApi")
    public static void executeWithResultString(
            AsyncTask<Void, Void, String> task) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {/*ww  w . j  a  v  a 2 s . c  o  m*/
            task.execute();
        }
    }

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

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

Related Tutorials