Example usage for android.os AsyncTask executeOnExecutor

List of usage examples for android.os AsyncTask executeOnExecutor

Introduction

In this page you can find the example usage for android.os AsyncTask executeOnExecutor.

Prototype

@MainThread
public final AsyncTask<Params, Progress, Result> executeOnExecutor(Executor exec, Params... params) 

Source Link

Document

Executes the task with the specified parameters.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static <T> void executeTask(AsyncTask<T, ?, ?> task, T... params) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {/*from w  w w  .jav  a2s . co m*/
        task.execute(params);
    }
}

From source file:Main.java

@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static <T> void executeOnExecutor(AsyncTask<T, ?, ?> task, T... params) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {/*  ww  w  .  j  ava2s  .c  o m*/
        task.execute(params);
    }
}

From source file:Main.java

private static <Params, Progress, Result> void executeAsyncTask(AsyncTask<Params, Progress, Result> task,
        Params... params) {/*from   w  w w . ja v a 2  s.  c  om*/
    if (Build.VERSION.SDK_INT >= 11) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {
        task.execute(params);
    }
}

From source file:Main.java

public static <Params, Progress, Result> void executeAsyncTask(AsyncTask<Params, Progress, Result> task,
        Params... params) {/* ww  w  .  java2s  .  com*/
    if (Build.VERSION.SDK_INT >= 11) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {
        task.execute(params);
    }
}

From source file:Main.java

public static void startWithParams(AsyncTask task, Object[] params) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {/*  w ww.ja  v a  2 s  .  c om*/
        task.execute(params);
    }
}

From source file:Main.java

public static <Params, Progress, Result> void exe(AsyncTask<Params, Progress, Result> asyncTask,
        Params... params) {//  ww w  .j  a  v  a  2s . c  o  m
    if (Build.VERSION.SDK_INT >= 11) {
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {
        asyncTask.execute(params);
    }
}

From source file:Main.java

@SafeVarargs
private static <Params, Progress, Result> void executeAsyncTask(AsyncTask<Params, Progress, Result> task,
        Params... params) {/*from   w w  w .  j a  va  2 s  .  c om*/
    if (Build.VERSION.SDK_INT >= 11) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {
        task.execute(params);
    }
}

From source file:Main.java

public static <Params, Progress, Result> void executeParallel(AsyncTask<Params, Progress, Result> task,
        Params... args) {//from   w ww  .j a va 2s.  c o m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
    } else {
        task.execute(args);
    }
}

From source file:Main.java

/**
 * In earlier versions of android, AsyncTasks where run on different threads
 * by employing a {@link ThreadPoolExecutor}. However, in more recent
 * versions, they all use only one single thread. If this behavior is not
 * desired, a new method/*  w  w  w  .  j  ava2s .  c  o m*/
 * {@link AsyncTask#executeOnExecutor(Executor, Object...)} was introduced.
 * However, this method is only available since honeycomb. This helper
 * method mitigates this change in the framework. For older versions it just
 * ignores the executor parameter.
 * 
 * @param task
 *            An {@link AsyncTask}
 * @param executor
 *            The executor which should host the task.
 * @param args
 *            Optional arguments to be passed to the task.
 */
@SuppressLint("NewApi")
public static <Params, Progress, Result> void executeOnExecutor(AsyncTask<Params, Progress, Result> task,
        Executor executor, Params... args) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(executor, args);
    } else {
        task.execute(args);
    }
}

From source file:com.commonsware.empub.ModelFragment.java

@TargetApi(11)
static public <T> void executeAsyncTask(AsyncTask<T, ?, ?> task, T... params) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {//  w  w  w .ja va  2s.  c om
        task.execute(params);
    }
}