Can an AsyncTask be cancelled while completing onPostExecute()?
Or is it that once doInBackground() is completed the task can no longer be cancelled?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 themayInterruptIfRunningparameter 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 afterdoInBackground(Object[])returns. Calling this method guarantees thatonPostExecute(Object)is never invoked. After invoking this method, you should check the value returned byisCancelled()periodically fromdoInBackground(Object[])to finish the task as early as possible.