AsyncTask won't stop even when the activity has destroyed

Posted by Raja on Stack Overflow See other posts from Stack Overflow or by Raja
Published on 2010-03-27T23:33:13Z Indexed on 2010/03/27 23:43 UTC
Read the original article Hit count: 196

Filed under:

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

© Stack Overflow or respective owner

Related posts about android