I have an AsyncTask
which dismisses the DialogFragment
. I am facing a problem when the AsyncTask
tries to dismiss the dialog after pressing the home button. dismissAllowingStateloss()
helps to this case, but one issue still remains. When I press home button and then rotate, the AsyncTask
tries to dismiss the activity, but as the orientation is changed, the activity calls onDestroy()
and recreates the stuff. As a result the DialogFragment
is on the screen again. setRetainInstance is set to true for the DialogFragment
. The normal dismiss()
raises IllegalStateException
by saying do not call after onSavedInstance()
.
Any idea how to fix this by keeping the DialogFragment
independent from the Activity
? I mean without putting tracking variables in the Activity
. I do not want to do this, because I do not want to write that stuff for each Activity
where I would use this dialog.