Inside of onPause, I’m calling cancel(true) on the AsyncTask called PlayTask. However, it still goes on merrily when I click on through to another activity. Why is my call to cancel not being respected?
FYI, here is the sequence of events:
CreateTrackActivity: btnPlay clicked
CreateTrackActivity: getting player for track
BasePlayerActivity : playing trac
BasePlayerActivity : Track playing
BasePlayerActivity : onPAUSE
BasePlayerActivity : play task cancelled
BaseActivity: onCreate
BasePlayerActivity: track received
BasePlayerActivity: track prepared
BasePlayerActivity: track setup finished
There are some unexpected reasons when you try to do asyncTask.cancel(true).
chance the task will not be interrupted. You can check what cancel(true) returns for you.
so, cancel(true) doesn’t necessarily stop the execution from doInBackground(). If cancel(true) returns true, all it means is the task won’t run the onPostExecute().
So, you have to check isCancelled() regularly in doInBackground().