Cancelling an ASyncTask
android
Solution
From what I understand the task is only running in the `doInBackground()` state, `onPostExecute()` means task has completed and can't be cancelled.
`cancel()` attempts to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the `mayInterruptIfRunning` parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.
Calling this method will result in `onCancelled(Object)` being invoked on the UI thread after `doInBackground(Object[])` returns. Calling this method guarantees that `onPostExecute(Object)` is never invoked. After invoking this method, you should check the value returned by `isCancelled()` periodically from `doInBackground(Object[])` to finish the task as early as possible.
Problem
Can an `AsyncTask` be cancelled while completing `onPostExecute()`? Or is it that once `doInBackground()` is completed the task can no longer be cancelled?