I have an AsyncTask
object which starts executing when the Activity
is created and does stuff in the background (downloads up to 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 AsyncTask
is still executing. (The data is saved correctly though)
I even tried to cancel the AsyncTask
in the onDestroy()
method of the activity but the logs still show AsyncTask
as running.
This is really strange behavior and would really be thankful if someone can tell me the correct procedure to stop/cancel the AsyncTask
.