On the orientation change, the Activity is recreated and Date Time Dialog also recreated. I want to save the State of the Date Time Dialog that has been changed by the User.
Before I Dismiss the Dialog I want to retained the state of the Date Time Dialog.
Note, I can dismiss the dialog in onSaveInstanceState, where I have the bundle available. But, it is also called when the activity goes in paused state, and in that case I don't want to dismiss the dialog. Hence, decided to dismiss it on onDestroy method, but I don't have the bundle object there. Which is why I am facing this problem. Is there any way to access the bundle in the onDestroy? Or any other suggestion for my problem would be appreciated.
@Override
protected void onDestroy() {
if(dateTimeDialog !=null && dateTimeDialog.isShowing())
{
//<HERE I WANT THE STATE TO BE SAVED IN THE BUNDLE>
dateTimeDialog.dismiss();
}
super.onDestroy();
}
Basically we lock the application if user move away from our application, and on unlock the screen and the dialog he is viewing are resumed. And if we dismissed the dialog on onSavedInstanceState, after unlocking the application it invokes onRestart, start and resume methods, where none of these have the instance of Bundle supplied as parameter.
Also, we have separate layouts for landscape & portrait because of which we cannot set the configChanges="orientation" in the manifest file.
You can still retain your Dialog states in onSaveIsntanceState()
, but only dismiss the dialog in onDestroy()
, which should satisfy your requirement. Though I am not sure what would a dialog dismissal in onDestroy()
accomplish.