本文整理汇总了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);
}
}