From what I understand, a task only works in the state doInBackground() , onPostExecute() means that the task is completed and cannot be canceled.
cancel() attempts to cancel the execution of this task. This attempt will fail if the task is already completed, already canceled or cannot be canceled for any other reason. If successful, and this task did not start when the cancel was called, this task should never be started. If the task is already running, the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted when it tries to stop the task.
A call to this method will result in a call to onCancelled(Object) in the user interface thread after doInBackground(Object[]) returns. Calling this method ensures that onPostExecute(Object) never called. After calling this method, you should periodically check the value returned by isCancelled() from doInBackground(Object[]) to complete the task as early as possible.
source share