本文整理匯總了Java中android.os.AsyncTask.cancel方法的典型用法代碼示例。如果您正苦於以下問題:Java AsyncTask.cancel方法的具體用法?Java AsyncTask.cancel怎麽用?Java AsyncTask.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.AsyncTask
的用法示例。
在下文中一共展示了AsyncTask.cancel方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onStop
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public void onStop() {
// Cancel all the async tasks
// please be aware that even after stopping, the async task continues until background task has finished
for (AsyncTask task : new AsyncTask[] { mDetailRowBuilderTask, mBackdropTask, mVideoInfoTask, mFullScraperTagsTask,
mSubtitleFilesListerTask, mPosterSaverTask, mBackdropSaverTask, mThumbnailAsyncTask}) {
if (task!=null) {
task.cancel(true);
}
}
//do not update remote resume
Log.d(TAG, "removeParseListener");
XmlDb.getInstance().removeParseListener(mRemoteDbObserver);
XmlDb.getInstance().removeResumeChangeListener(this);
super.onStop();
}
示例2: unregisterAsyncTask
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* 如果任務未執行完畢,則取消任務
*
* @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);
}
}
}
}
示例3: cancel
import android.os.AsyncTask; //導入方法依賴的package包/類
private synchronized void cancel() {
AsyncTask<?, ?, ?> task = inactivityTask;
if (task != null) {
task.cancel(true);
inactivityTask = null;
}
}
示例4: cancel
import android.os.AsyncTask; //導入方法依賴的package包/類
private synchronized void cancel() {
AsyncTask<?,?,?> task = inactivityTask;
if (task != null) {
task.cancel(true);
inactivityTask = null;
}
}
示例5: clearAllTasks
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public void clearAllTasks() {
if(tasks == null)
return;
for (AsyncTask task : tasks) {
try {
if(task.getStatus() != AsyncTask.Status.FINISHED)
task.cancel(true);
}
catch (Exception ignore){}
}
tasks.clear();
}
示例6: cancel
import android.os.AsyncTask; //導入方法依賴的package包/類
private synchronized void cancel() {
AsyncTask<?, ?, ?> task = inactivityTask;
if (task != null) {
task.cancel(true);
inactivityTask = null;
}
}
示例7: unsubscribeFromBackgroundTask
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public void unsubscribeFromBackgroundTask(int taskId) {
AsyncTask backgroundTask = backgroundTasks.remove(taskId);
if (backgroundTask != null) {
// Passing in "false" because the already running background task should not be interrupted.
// If the task has completed or is marked as canceled we don't care, therefore the return value won't be checked.
backgroundTask.cancel(false);
}
}
示例8: cancelAll
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public void cancelAll() {
final Iterator<TextView> textViewIterator = tasks.keySet().iterator();
while (textViewIterator.hasNext()) {
final AsyncTask existingTask = tasks.get(textViewIterator.next());
if (existingTask != null) {
existingTask.cancel(false);
textViewIterator.remove();
}
}
}
示例9: onPause
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
protected void onPause() {
AsyncTask<?,?,?> task = backgroundTask;
if (task != null) {
task.cancel(true);
backgroundTask = null;
}
super.onPause();
}
示例10: clearAsyncTask
import android.os.AsyncTask; //導入方法依賴的package包/類
protected void clearAsyncTask() {
Iterator<AsyncTask<Void, Void, Boolean>> iterator = mAsyncTasks
.iterator();
while (iterator.hasNext()) {
AsyncTask<Void, Void, Boolean> asyncTask = iterator.next();
if (asyncTask != null && !asyncTask.isCancelled()) {
asyncTask.cancel(true);
}
}
mAsyncTasks.clear();
}
示例11: cancel
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public void cancel(final ImageView imageView) {
final AsyncTask existingTask = tasks.get(imageView);
if (existingTask != null) {
existingTask.cancel(false);
tasks.remove(imageView);
}
}
示例12: cancel
import android.os.AsyncTask; //導入方法依賴的package包/類
synchronized void cancel() {
AsyncTask<?, ?, ?> task = inactivityTask;
if (task != null) {
task.cancel(true);
inactivityTask = null;
}
}
示例13: cancel
import android.os.AsyncTask; //導入方法依賴的package包/類
private synchronized void cancel() {
AsyncTask<?,?,?> task = inactivityTask;
if (task != null) {
task.cancel(true);
inactivityTask = null;
}
}
示例14: cancelTask
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* 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);
}
}