Java Code Examples for android.os.AsyncTask#executeOnExecutor()
The following examples show how to use
android.os.AsyncTask#executeOnExecutor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactsManager.java From react-native-contacts with MIT License | 6 votes |
/** * Retrieves contacts. * Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy otherwise. * * @param callback user provided callback to run at completion */ private void getAllContacts(final Callback callback) { AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() { @Override protected Void doInBackground(final Void ... params) { Context context = getReactApplicationContext(); ContentResolver cr = context.getContentResolver(); ContactsProvider contactsProvider = new ContactsProvider(cr); WritableArray contacts = contactsProvider.getContacts(); callback.invoke(null, contacts); return null; } }; myAsyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }
Example 2
Source File: ContactsManager.java From react-native-contacts with MIT License | 6 votes |
@ReactMethod public void getCount(final Callback callback) { AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() { @Override protected Void doInBackground(final Void ... params) { Context context = getReactApplicationContext(); ContentResolver cr = context.getContentResolver(); ContactsProvider contactsProvider = new ContactsProvider(cr); Integer contacts = contactsProvider.getContactsCount(); callback.invoke(contacts); return null; } }; myAsyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }
Example 3
Source File: ContactsManager.java From react-native-contacts with MIT License | 6 votes |
/** * Retrieves contacts matching String. * Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy otherwise. * * @param searchString String to match * @param callback user provided callback to run at completion */ @ReactMethod public void getContactsMatchingString(final String searchString, final Callback callback) { AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() { @Override protected Void doInBackground(final Void ... params) { Context context = getReactApplicationContext(); ContentResolver cr = context.getContentResolver(); ContactsProvider contactsProvider = new ContactsProvider(cr); WritableArray contacts = contactsProvider.getContactsMatchingString(searchString); callback.invoke(null, contacts); return null; } }; myAsyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }
Example 4
Source File: AsyncCheckFeed.java From rss with GNU General Public License v3.0 | 5 votes |
static AsyncTask<Void, Void, IndexItem> newInstance(FeedsActivity activity, Dialog dialog, IndexItem oldIndexItem) { AsyncTask<Void, Void, IndexItem> task = new AsyncCheckFeed(activity, dialog, oldIndexItem); task.executeOnExecutor(SERIAL_EXECUTOR); return task; }
Example 5
Source File: TaskUtils.java From Qshp with MIT License | 5 votes |
public static <Params, Progress, Result> void executeAsyncTask( AsyncTask<Params, Progress, Result> task, Params... params) { if (Build.VERSION.SDK_INT >= 11) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); } else { task.execute(params); } }
Example 6
Source File: ApiUtils.java From Alibaba-Android-Certification with MIT License | 5 votes |
public static void execute(AsyncTask<Object, Integer,Object> task,Object...args) { if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) { if (threadPool==null) { threadPool=Executors.newCachedThreadPool(); } task.executeOnExecutor(threadPool,args); }else { task.execute(args); } }
Example 7
Source File: ImageProvider.java From mobile-manager-tool with MIT License | 5 votes |
private void asyncLoad(String tag, ImageView imageView, AsyncTask<String, Integer, Bitmap> task) { Set<ImageView> pendingImages = pendingImagesMap.get(tag); if (pendingImages == null) { pendingImages = Collections.newSetFromMap(new WeakHashMap<ImageView, Boolean>()); // create weak set pendingImagesMap.put(tag, pendingImages); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } pendingImages.add(imageView); imageView.setTag(tag); imageView.setImageDrawable(null); }
Example 8
Source File: Utils.java From tup.dota2recipe with Apache License 2.0 | 5 votes |
/** * execute AsyncTask * * @param task */ @SuppressLint("NewApi") public static <Params, Progress, Result> void executeAsyncTask( AsyncTask<Params, Progress, Result> loaderTask, Params... params) { if (loaderTask == null) { return; } if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { loaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); } else { loaderTask.execute(params); } }
Example 9
Source File: SystemPropertiesTests.java From azure-mobile-apps-android-client with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") private void executeTask(AsyncTask<Void, Void, Void> task) { // If it's running with Honeycomb or greater, it must execute each // request in a different thread if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { task.execute(); } }
Example 10
Source File: MusicBrowser.java From DMAudioStreamer with Apache License 2.0 | 5 votes |
public static void loadMusic(final Context context, final MusicLoaderListener loaderListener) { final AsyncTask<Void, Void, Void> loadTask = new AsyncTask<Void, Void, Void>() { String[] resp = {"", ""}; List<MediaMetaData> listMusic = new ArrayList<>(); @Override protected Void doInBackground(Void... voids) { //resp = getDataResponse(); String response = loadJSONFromAsset(context); listMusic = getMusicList(response, "music"); return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); if (loaderListener != null && listMusic != null && listMusic.size() >= 1) { loaderListener.onLoadSuccess(listMusic); } else { loaderListener.onLoadFailed(); } } }; loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
Example 11
Source File: ThreadUtil.java From letv with Apache License 2.0 | 5 votes |
public static <A, B, C> void execUi(AsyncTask<A, B, C> task, A... params) { if (task != null) { if (VERSION.SDK_INT < 11) { task.execute(params); } else { task.executeOnExecutor(uiExecutor, params); } } }
Example 12
Source File: WatchUpdaterService.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
private void executeTask(AsyncTask task, DataMap... parameters) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) parameters); // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // } else { // task.execute(); // } }
Example 13
Source File: Chest.java From Iron with Apache License 2.0 | 5 votes |
public void removeAllAsync() { AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { deleteAll(); return null; } }; if (Build.VERSION.SDK_INT > 10) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { task.execute(); } }
Example 14
Source File: SubsamplingScaleImageView.java From subsampling-scale-image-view with Apache License 2.0 | 4 votes |
private void execute(AsyncTask<Void, Void, ?> asyncTask) { asyncTask.executeOnExecutor(executor); }
Example 15
Source File: BaseRecipientAdapter.java From talk-android with MIT License | 4 votes |
private static void fetchPhotoAsync(final RecipientEntry entry, final Uri photoThumbnailUri, final BaseAdapter adapter, final ContentResolver mContentResolver) { final AsyncTask<Void, Void, byte[]> photoLoadTask = new AsyncTask<Void, Void, byte[]>() { @Override protected byte[] doInBackground(Void... params) { // First try running a query. Images for local contacts are // loaded by sending a query to the ContactsProvider. final Cursor photoCursor = mContentResolver.query( photoThumbnailUri, PhotoQuery.PROJECTION, null, null, null); if (photoCursor != null) { try { if (photoCursor.moveToFirst()) { return photoCursor.getBlob(PhotoQuery.PHOTO); } } finally { photoCursor.close(); } } else { // If the query fails, try streaming the URI directly. // For remote directory images, this URI resolves to the // directory provider and the images are loaded by sending // an openFile call to the provider. try { InputStream is = mContentResolver.openInputStream( photoThumbnailUri); if (is != null) { byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int size; while ((size = is.read(buffer)) != -1) { baos.write(buffer, 0, size); } } finally { is.close(); } return baos.toByteArray(); } } catch (IOException ex) { // ignore } } return null; } @Override protected void onPostExecute(final byte[] photoBytes) { entry.setPhotoBytes(photoBytes); if (photoBytes != null) { mPhotoCacheMap.put(photoThumbnailUri, photoBytes); if (adapter != null) adapter.notifyDataSetChanged(); } } }; photoLoadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }
Example 16
Source File: CompatUtils.java From microMathematics with GNU General Public License v3.0 | 4 votes |
@SafeVarargs public static <T> void executeAsyncTask(AsyncTask<T, ?, ?> asyncTask, T... params) { asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); }
Example 17
Source File: SubsamplingScaleImageView.java From PictureSelector with Apache License 2.0 | 4 votes |
private void execute(AsyncTask<Void, Void, ?> asyncTask) { asyncTask.executeOnExecutor(executor); }
Example 18
Source File: SubsamplingScaleImageViewDragClose.java From imsdk-android with MIT License | 4 votes |
private void execute(AsyncTask<Void, Void, ?> asyncTask) { asyncTask.executeOnExecutor(executor); }
Example 19
Source File: AsyncNavigationAdapter.java From rss with GNU General Public License v3.0 | 4 votes |
public static void run(Activity activity) { AsyncTask<String, Void, String[][]> task = new AsyncNavigationAdapter(activity); task.executeOnExecutor(THREAD_POOL_EXECUTOR); }
Example 20
Source File: HoneycombAsyncTaskExecInterface.java From reacteu-app with MIT License | 4 votes |
@Override public <T> void execute(AsyncTask<T,?,?> task, T... args) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args); }