Java Code Examples for android.os.AsyncTask#getStatus()
The following examples show how to use
android.os.AsyncTask#getStatus() .
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: BaseActivity.java From Simpler with Apache License 2.0 | 5 votes |
/** * 如果任务未执行完毕,则取消任务 * * @param clazz Activity Class */ public void unregisterAsyncTask(Class<? extends BaseActivity> clazz) { ArrayList<AsyncTask> tasks = new ArrayList<>(mTasks.removeAll(clazz)); int size = tasks.size(); if (size > 0) { for (int i = 0; i < size; i++) { AsyncTask task = tasks.get(i); //you may call the cancel() method but if it is not handled in doInBackground() method if (task != null && task.getStatus() != AsyncTask.Status.FINISHED) { task.cancel(true); } } } }
Example 2
Source File: DynamicTaskUtils.java From dynamic-utils with Apache License 2.0 | 5 votes |
/** * Try to execute the supplied async task. * * @param asyncTask The async task to be executed. * * @see AsyncTask#execute(Object[]) */ @SuppressWarnings("unchecked") public static void executeTask(@Nullable AsyncTask asyncTask) { try { if (asyncTask != null && asyncTask.getStatus() != AsyncTask.Status.RUNNING) { asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) null); } } catch (Exception ignored) { } }
Example 3
Source File: DynamicTaskUtils.java From dynamic-utils with Apache License 2.0 | 5 votes |
/** * Try to cancel the supplied async task. * * @param asyncTask The async task to be cancelled. * * @see AsyncTask#cancel(boolean) */ public static void cancelTask(@Nullable AsyncTask asyncTask) { try { if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING) { asyncTask.cancel(true); } } catch (Exception ignored) { } }
Example 4
Source File: LNReaderApplication.java From coolreader with MIT License | 5 votes |
public boolean addTask(String key, AsyncTask<?, ?, ?> task) { synchronized (lock) { if (runningTasks.containsKey(key)) { AsyncTask<?, ?, ?> tempTask = runningTasks.get(key); if (tempTask != null && tempTask.getStatus() != Status.FINISHED) return false; } runningTasks.put(key, task); return true; } }
Example 5
Source File: LatinIMEUtil.java From hackerskeyboard with Apache License 2.0 | 2 votes |
/** * Cancel an {@link AsyncTask}. * * @param mayInterruptIfRunning <tt>true</tt> if the thread executing this * task should be interrupted; otherwise, in-progress tasks are allowed * to complete. */ public static void cancelTask(AsyncTask<?, ?, ?> task, boolean mayInterruptIfRunning) { if (task != null && task.getStatus() != AsyncTask.Status.FINISHED) { task.cancel(mayInterruptIfRunning); } }