List of usage examples for android.os AsyncTask THREAD_POOL_EXECUTOR
Executor THREAD_POOL_EXECUTOR
To view the source code for android.os AsyncTask THREAD_POOL_EXECUTOR.
Click Source Link
From source file:Main.java
public static void start(AsyncTask task) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[] {}); } else {/*from w w w . j a va 2s . co m*/ task.execute(new Void[] {}); } }
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 w w . j av a 2 s . co 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: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 w w w . jav a 2 s . co m task.execute(params); } }
From source file:Main.java
public static void mediaScannerCall(final Context context, final File file) { new AsyncTask<Void, Void, Void>() { @Override/*from w w w . j a v a 2s .co m*/ protected Void doInBackground(Void... params) { MediaScannerConnection.scanFile(context, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { Log.i("ExternalStorage", "Scanned " + path + ":"); Log.i("ExternalStorage", "-> uri=" + uri); } }); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null); }
From source file:Main.java
/** * Execute an {@link AsyncTask} on a thread pool * * @param <T> Task argument type/* w w w. java 2 s. c om*/ * @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[])} */ @SuppressLint("NewApi") public static <T> WeakReference<AsyncTask<T, ?, ?>> execute(final boolean forceSerial, final AsyncTask<T, ?, ?> task, final T... args) { final WeakReference<AsyncTask<T, ?, ?>> taskReference = new WeakReference<AsyncTask<T, ?, ?>>(task); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) { throw new UnsupportedOperationException("This class can only be used on API 4 and newer."); } try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || forceSerial) { taskReference.get().execute(args); } else { taskReference.get().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args); } } catch (Exception e) { e.printStackTrace(); } return taskReference; }
From source file:Main.java
/** * Execute an {@link AsyncTask} on a thread pool * //ww w . ja v a 2 s.com * @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:Main.java
/** * Execute an {@link AsyncTask} on a thread pool * /*from ww w . j ava 2s . 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) { final WeakReference<AsyncTask<T, ?, ?>> taskReference = new WeakReference<AsyncTask<T, ?, ?>>(task); 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) { taskReference.get().execute(args); } else { taskReference.get().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args); } }
From source file:Main.java
@SafeVarargs private static <Params, Progress, Result> void executeAsyncTask(AsyncTask<Params, Progress, Result> task, Params... params) {/*from w w w .jav a 2s . c om*/ if (Build.VERSION.SDK_INT >= 11) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); } else { task.execute(params); } }
From source file:com.jrummyapps.busybox.dialogs.AppletUsageDialog.java
public static void show(Activity activity, String applet) { new AppletHelpTask(activity, applet).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:ar.uba.fi.splitapp.MockServer.java
public static void sendGroupMessage(String message, String groupName, String[] friendList) { if (mRoom == null) { return;//from w w w .ja va 2 s. co m } mRoom.addResponse(message, Profile.getCurrentProfile().getId()); AddGroupResponseTask task = new AddGroupResponseTask(groupName, friendList); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }