Android Asyntask: Use weak reference for context to avoid device rotate screen
Somewhere in your AsyncTask you’ll want to pass in your activity. Then you’ll save that reference in a weak reference. Then you can dereference and use it again in onPostExecute. Class member: WeakReference<Activity> weakActivity; Somewhere in AsyncTask, probably either constructor or onPreExecute: weakActivity = new WeakReference<Activity>(activity); In onPostExecute: Activity activity = weakActivity.get(); if (activity != … Read more