Activities provides a convenient and manageable dialog box mechanism for creating, saving, and replying, such as Oncreatedialog (int), onpreparedialog (int, Dialog), showDialog (int), Methods such as DismissDialog (int), if these methods are used, activity will return the activity-Managed Dialog (dialog) through the Getowneractivity () method.
Oncreatedialog (int): When you use this callback function, the Android system effectively sets the activity to be the owner of each dialog box, thus automatically managing the status of each dialog box and attaching it to the activity. In this way, each dialog box inherits the specific properties of the activity. For example, when a dialog box opens, the menu key is displayed as a menu of options defined by the activity, and the volume key modifies the audio stream used by the activity.
ShowDialog (int): When you want to display a dialog box, call the showDialog (int id) method and pass an integer that uniquely identifies the dialog box. When the dialog box is first requested, Android calls Oncreatedialog (int id) from your activity, and you should initialize this dialog box here dialog. This callback method is passed the same ID as the ShowDialog (int id). When you create this dialog box, the object is returned at the end of the activity.
Onpreparedialog (int, Dialog): Android also calls the optional callback function onpreparedialog (int ID, Dialog) before the dialog box is displayed. You can define this method if you want to change any of its properties when the dialog box is opened. This method is called every time the dialog box is opened, and Oncreatedialog (int) is called only when the dialog box is opened for the first time. If you do not define Onpreparedialog (), then this dialog will remain the same as it was last opened. This method is also passed as the ID of the dialog box, and the dialog object created in Oncreatedialog ().
DismissDialog (int): When you are ready to close the dialog box, you can eliminate it by calling dismiss () on the dialog box. If necessary, you can also invoke the dismissdialog (int id) method from this activity, which will actually call the dismiss () method for you to this dialog box. If you want to use the Oncreatedialog (int id) method to manage the state of your dialog (as discussed in the previous section), then each time your dialog box is cleared, the state of the dialog object will be retained by that activity. If you decide that you no longer need this object or clear the state is important, then you should call Removedialog (int id). This will remove any internal object references and if this dialog box is being displayed, it will be eliminated.
The entire life cycle of Android Dialog