/** Cancel all registered tasks. */ public void cancellAllInterrupt() { synchronized (mTasks) { for (EmailAsyncTask<?, ?, ?> task : mTasks) { task.cancel(true); } mTasks.clear(); } }
@Override public void onPostExecute(Result2 result) { mOwner.unregisterSelf(); if (mOwner.mCancelled) { mOwner.onCancelled(result); } else { mOwner.onSuccess(result); } }
private static EmailAsyncTask<Void, Void, Void> runAsyncInternal( Executor executor, final Runnable runnable) { EmailAsyncTask<Void, Void, Void> task = new EmailAsyncTask<Void, Void, Void>(null) { @Override protected Void doInBackground(Void... params) { runnable.run(); return null; } }; return task.executeInternal(executor, false, (Void[]) null); }
/** * Cancel all instances of the same class as {@code current} other than {@code current} itself. */ /* package */ void cancelOthers(EmailAsyncTask<?, ?, ?> current) { final Class<?> clazz = current.getClass(); synchronized (mTasks) { final ArrayList<EmailAsyncTask<?, ?, ?>> toRemove = new ArrayList<EmailAsyncTask<?, ?, ?>>(); for (EmailAsyncTask<?, ?, ?> task : mTasks) { if ((task != current) && task.getClass().equals(clazz)) { task.cancel(true); toRemove.add(task); } } for (EmailAsyncTask<?, ?, ?> task : toRemove) { mTasks.remove(task); } } }
@Override public void onCancelled(Result2 result) { mOwner.unregisterSelf(); mOwner.onCancelled(result); }
@Override protected Result2 doInBackground(Params2... params) { return mOwner.doInBackground(params); }