0

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 :-)

Swift
  • 829
  • 2
  • 12
  • 33

1 Answers1

0

Include the following to your activity tag in AndroidManifest.xml file.

android:configChanges="orientation|screenSize"

You can refer this for better understanding.

Community
  • 1
  • 1
SweetWisher ツ
  • 7,296
  • 2
  • 30
  • 74
  • I can not use android:configChanges =" orientation| screenSize " this because I am using diffrent layouts for tablets and Phones. – Swift Oct 22 '13 at 12:33