Code example for AsyncTask

Methods: cancel, getStatus

0
     * @param theTask {@link AsyncTask} to be checked. 
     * @return True if the task is running, false otherwise. 
     */ 
    public static boolean isRunning(final AsyncTask<?, ?, ?> theTask) {
        return (theTask != null && 
                theTask.getStatus().equals(AsyncTask.Status.RUNNING));
    } 
 
    /** 
     * Abort the running task. 
     * 
     * @param theTask 
     * @return True if the task has been successfully aborted. False otherwise. 
     */ 
    public static boolean abort(AsyncTask<?, ?, ?> theTask) {
        if (!AsyncTaskUtils.isRunning(theTask)) {
            return false; 
        } 
        theTask.cancel(true);
        theTask = null;
        return true; 
    } 
}