To show the Message Dialog while screen is turned on and also retained the dialog on orientation changed.
public void onDestroy()
{ //savedMessageDialog id represents the current MessageDialogId
//dismiss the message dialog if message id displayed.
int savedMessageDialogId = MessageDialog.getSavedMessageDialogId();
if(savedMessageDialogId == MSG_BACK_DATE_WARNING){
MessageDialog.dismissMessageDialog();
}
}
and My MessageDialog extends the DialogFragment hence i put this same code in onSavedInstancestate it's working properly no issues Succcess !!!
While I put this code in onDestroy it is creating the multiple instances while many times I changed the orientation and also note that I will dismiss the dialog because of when I am back from turned off to Turn on the Device My dialog shown up. and My MessageDialog internally uses the AlertDialog.... in that
private static MessageDialog currentMessageDialog = null;
public static void dismissMessageDialog()
{
if (MessageDialog != null && MessageDialog.isAdded())
{
try
{
currentMessageDialog.dismiss();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
finally
{
currentMessageDialog = null;
}
}
}
so please Let me know why i can't dismiss the dialog in onDestroy and why multiple instances are created for MessageDialog ? Please suggest me some good solution :-)