OK. I have worked it out. I am not sure which API version it was fixed in, but if you look at the code for Gingerbread there is a clear race condition in the cancel()
handling. The GUI thread code which processes the MESSAGE_POST_RESULT
message from the background calls onPostExecute()
regardless of whether or not the task was cancelled.
It turns out that the fix is quite simple. All I need to do is add my own check of isCancelled()
before executing my onPostExecute()
logic.
The Gingerbread code receives MESSAGE_POST_RESULT
and calls finish()
. Then finish()
calls onPostExecute()
.