In the onDestroy() Method of Activity, set the flag to indicate that the activity has been destroyed.
Also, in AsyncTask add WeakReference to Activity instead of the regular link.
In the onPostExecute() AsyncTask activity is still alive if WeakReference still matters and the Activity itself has a flag set to false.
source share