Android AsyncTask won’t stop when cancelled, why?

Keep in mind that your Activity and your AsyncTask are two separate threads. So even if you cancel the AsyncTask, the code to cancel the task may not run yet! That’s why you are seeing the AsyncTask still running even after fixing your bug. I don’t think the status will change until doInBackground() in your AsyncTask has completed. (So make sure you’re checking isCancelled() and returning early when you’ve been cancelled!)

Leave a Comment