Example usage for android.os AsyncTask execute

List of usage examples for android.os AsyncTask execute

Introduction

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

Prototype

@MainThread
public static void execute(Runnable runnable) 

Source Link

Document

Convenience version of #execute(Object) for use with a simple Runnable object.

Usage

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 {/*from  ww  w .  j ava  2s . 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 ww w. j  ava 2s  .co m*/
    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) {/*from   w  ww . j  a v a  2 s  . co  m*/
    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 {//from ww w  . j a v a2 s  . c o  m
        task.execute(params);
    }
}

From source file:Main.java

@SuppressLint("NewApi")
public static <Params, Progress, Result> void executeAsyncTask(AsyncTask<Params, Progress, Result> task,
        Params... params) {//from w w  w .j a v a2s.  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 exe(AsyncTask<Params, Progress, Result> asyncTask,
        Params... params) {//from  w  w w . j a  v a 2  s  .  co m
    if (Build.VERSION.SDK_INT >= 11) {
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } else {
        asyncTask.execute(params);
    }
}

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//from   w  ww. j  a va  2  s  .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:Main.java

public static <Params, Progress, Result> void executeParallel(AsyncTask<Params, Progress, Result> task,
        Params... args) {//from w  w w  .  j  av a  2s  . c  om
    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

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

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.  j av  a 2 s  .  c om*/
        task.execute(params);
    }
}