0
votes

According to document here

Calling this method will result in onCancelled(Object) being invoked on the UI thread after doInBackground(Object[]) returns

However, in my case onCancelled(Object) is called right after I call cancel method. My question: Is the document wrong?

2

2 Answers

0
votes

I experineced the similar problem. After calling cancel() my task continued to run. That was valid for Android 2.2 and 2.3. I ended up with checking regularly isCancelled() inside doInBackground. And the behavior was the same either you call cancel(true) or cancel(false).

0
votes

An AsyncTask executing normally can be in four states: not yet executed, executing, finished, and canceled. The cancel() method does not work if the task is already finished or canceled. If the task is executing, doInBackground() will have to complete before onCancelled() is called. However, if the task has not started executing, onCancelled() will be called right away and you will not be able to execute the task.