AsyncTask won't stop even when the activity has destroyed
- by Raja
Hi all,
I have an AsyncTask object which starts executing when the activity is created and does stuff in the background (downloads upto 100 images). Everything works fine but there is this peculiar behavior which i'm not able to understand.
For eg: when the android screen's orientation changes then the activity is destroyed and created again. So I override the onRetainNonConfigurationInstance() method and save all the downloaded data executed in the AsyncTask. My purpose of doing this is to not have AsyncTask run each time activity is destroyed-created during orientation changes, but as i can see in my logs the previous AsynTask is still executing. (The data is saved correctly though)
I even tried to cancel the AsynTask in the onDestroy() method of the activity but the logs still show AsynTask as running.
This is really strange behavior and would really be thankful if someone can tell me the correct procedure to stop/cancel the AsynTask.
Thanks