I had an issue recently where I called an asynctask from an activity and returned some data. My UI would freeze up and I was getting an ANR. I seemed to have resolved it by using a combination of solutions for both things I thought it could be, both the asynctask and the arraylist I was implementing.
I had a callback on the asynctask to load the data asynchronously. I guessed, though I had a hard time figuring out, that the asynctask was being retained after onpostexecute? In any case, I called this.cancel() in onpostexecute.
After reading up a bit on it, it seems that the cancel() function on schedules the task to be cancelled and that it can possibly persist after the request is made. So I must ask is there a better way to cancel the asynctask after you are finished with it? Will cancel() be sufficient in most cases? Are there ways to avoid having to call cancel() at all while implementing a call back.