In Apress Pro Android 4 the author has said that:
[…] context of currently running activity will no longer be valid when the device is rotated. […] One approach is to use a weak reference to the activity instead of a hard reference […]
But the author just suggest this, and does not tell how it is done. Who has done this before please give me an example.
Somewhere in your
AsyncTaskyou’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 inonPostExecute.Class member:
Somewhere in
AsyncTask, probably either constructor oronPreExecute:In
onPostExecute: