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

/**
 * Runs an AsyncTask. These are always executed in parallel, independently of the device's API level.
 * @param task Task to be run.//from   w ww.j a va 2s .c  o  m
 * @param params Task parameters.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static <Params> void executeAsyncTask(AsyncTask<Params, ?, ?> task, Params... params) {
    // By default, in Honeycomb and later AsyncTasks execute serially, while they execute
    // in parallel (using a thread pool) in earlier versions. Force parallelism here.
    if (isHoneycomb())
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    else
        task.execute(params);
}

From source file:org.piwik.sdk.TrackerBulkURLProcessor.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static <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 {/*from   w  ww .j a va2s  .  c  om*/
        task.execute(params);
    }
}

From source file:com.kasungunathilaka.sarigama.util.PlayerQueue.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11
public static <T> void executeAsyncTask(AsyncTask<T, ?, ?> asyncTask, T... params) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    else/*from  ww w .  j a  va  2  s . c  o  m*/
        asyncTask.execute(params);
}

From source file:Main.java

/**
 * Execute an {@link AsyncTask} on a thread pool
 * /*from w ww  .  j  a  v a 2  s . c  o  m*/
 * @param forceSerial True to force the task to run in serial order
 * @param task Task to execute
 * @param args Optional arguments to pass to
 *            {@link AsyncTask#execute(Object[])}
 * @param <T> Task argument type
 */
@SuppressLint("NewApi")
public static <T> void execute(final boolean forceSerial, final AsyncTask<T, ?, ?> task, final T... args) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
        throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || forceSerial) {
        task.execute(args);
    } else {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
    }
}

From source file:com.battlelancer.seriesguide.util.Utils.java

/**
 * Executes the {@link android.os.AsyncTask} on the {@link android.os.AsyncTask#SERIAL_EXECUTOR},
 * e.g. one after another./* w ww  . j a  va2s.  c  o m*/
 *
 * <p> This is useful for executing non-blocking operations (e.g. NO network activity, etc.).
 */
@SafeVarargs
public static <T> AsyncTask executeInOrder(AsyncTask<T, ?, ?> task, T... args) {
    return task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, args);
}

From source file:com.intel.iotkitlib.LibModules.ParentModule.java

protected boolean invokeHttpExecuteOnURL(String url, AsyncTask<String, Void, CloudResponse> httpTask,
        String taskDescription) {
    //try {/*from w ww.j av a2s  .c  om*/
    //httpTask.execute(url).get();
    if (url == null) {
        Log.i(TAG, "Http request Url Cannot be null");
    }
    httpTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
    return true;
    //}
    /*catch (InterruptedException e) {
    Log.e(taskDescription, "InterruptedException", e);
    return false;
    } catch (ExecutionException e) {
    Log.e(taskDescription, "ExecutionException", e);
    return false;
    }*/
}

From source file:fr.simon.marquis.preferencesmanager.ui.AppListActivity.java

private void checkRoot() {
    AsyncTask<Void, Void, Boolean> checking = new AsyncTask<Void, Void, Boolean>() {

        @Override/* www  .j  av  a  2s .com*/
        protected Boolean doInBackground(Void... params) {
            return RootTools.isRootAvailable() && RootTools.isAccessGiven() && RootTools.isBusyboxAvailable();
        }

        @Override
        protected void onPostExecute(Boolean hasRoot) {
            super.onPostExecute(hasRoot);
            isRootAccessGiven = hasRoot;
            if (!hasRoot) {
                Utils.displayNoRoot(getFragmentManager());
            }
        }
    };
    checking.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
}

From source file:org.brandroid.openmanager.util.EventHandler.java

public static AsyncTask execute(AsyncTask job, String... params) {
    if (OpenExplorer.BEFORE_HONEYCOMB)
        job.execute((Object[]) params);
    else/*w ww . ja  v  a  2 s.  c om*/
        job.executeOnExecutor(getExecutor(), (Object[]) params);
    return job;
}

From source file:org.brandroid.openmanager.util.EventHandler.java

public static AsyncTask execute(AsyncTask job, OpenFile... params) {
    if (OpenExplorer.BEFORE_HONEYCOMB)
        job.execute((Object[]) params);
    else/*from  w  ww.ja va  2s  .c o m*/
        job.executeOnExecutor(getExecutor(), (Object[]) params);
    return job;
}

From source file:org.jboss.aerogear.android.sync.SyncService.java

private void connectAsync() {
    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {

        @Override/*ww w .  j  a  v  a2  s.  co  m*/
        protected Void doInBackground(Void... params) {
            try {
                syncClient.connect();
            } catch (Exception ex) {
                Log.e(TAG, ex.getMessage(), ex);
                throw new RuntimeException(ex);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            for (SyncServerConnectionListener listener : connectionListeners) {
                listener.onConnected();
            }
        }

    };

    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}