Example usage for android.os AsyncTask cancel

List of usage examples for android.os AsyncTask cancel

Introduction

In this page you can find the example usage for android.os AsyncTask cancel.

Prototype

public final boolean cancel(boolean mayInterruptIfRunning) 

Source Link

Document

Attempts to cancel execution of this task.

Usage

From source file:Main.java

public static void cancelAsyncTask(AsyncTask<?, ?, ?> task) {

    if (task != null) {
        task.cancel(true);
    }
}

From source file:Main.java

static boolean killAsync(AsyncTask asyncTask) {
    return asyncTask != null && !asyncTask.isCancelled() && asyncTask.cancel(true);
}

From source file:Main.java

/**
 * Cancels asynchronous tasks immediately.
 * @param tasks array of asynchronous tasks
 *//*from ww  w .  j a  v a 2 s .c  o  m*/
public static void cancelTasks(AsyncTask<?, ?, ?>... tasks) {
    if (null != tasks) {
        for (AsyncTask<?, ?, ?> task : tasks) {
            if (null != task)
                task.cancel(true);
        }
    }
}

From source file:Main.java

public static boolean cancelTask(AsyncTask<?, ?, ?> paramAsyncTask) {
    if (!isAsynctaskFinished(paramAsyncTask))
        return paramAsyncTask.cancel(true);
    return false;
}

From source file:Main.java

/**
 * Cancel an {@link AsyncTask}./*from w  ww. j a v  a  2  s  .c om*/
 *
 * @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);
    }
}

From source file:net.archenemy.archenemyapp.presenter.BitmapUtility.java

/**
 * Cancels all background tasks that haven't completed. Should be called from
 * activity's onDestroy() method.//from w  w  w.  j a va  2 s  . co  m
 */
public static void onDestroy() {
    if (!tasks.isEmpty()) {
        for (final AsyncTask task : tasks) {
            task.cancel(true);
        }
        tasks.clear();
    }
    Log.i(TAG, "All async tasks cancelled.");
}

From source file:com.packpublishing.asynchronousandroid.chapter3.MyPuppyAlbumActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    // Cancel Pending Tasks
    for (AsyncTask task : photoAsyncTasks) {
        if (task.getStatus() != AsyncTask.Status.FINISHED) {
            task.cancel(true);
        }//from ww  w .j ava  2  s . c o m
    }
    photoAsyncTasks.clear();
}

From source file:com.grabtaxi.roadboardscan.zxing.InactivityTimer.java

/**
 * ?//from  w w  w .  j  a  v  a 2  s. c  o m
 */
private synchronized void cancel() {
    AsyncTask<?, ?, ?> task = inactivityTask;
    if (task != null) {
        task.cancel(true);
        inactivityTask = null;
    }
}

From source file:org.akop.crosswords.fragment.BaseFragment.java

protected void cancelAllTasks() {
    synchronized (mTaskLock) {
        for (AsyncTask task : mActiveTasks) {
            try {
                task.cancel(false);
            } catch (Exception e) {
                e.printStackTrace();//from w  w  w  . j a  v a2 s. c  o m
            }
        }

        mActiveTasks.clear();
    }
}

From source file:simple.android.compat.SimpleFragmentActivity.java

@Override
protected void onDestroy() {
    if (isFinishing()) {
        ArrayList<AsyncTask<Void, Void, Void>> tasks = mState.getAsyncTasks();
        for (AsyncTask<Void, Void, Void> asyncTask : tasks) {
            asyncTask.cancel(false); // TODO: should this be true?
        }//from  w w  w .  j  a v  a  2  s  . c  om
    }
    super.onDestroy();
}