tags:

views:

235

answers:

1

Hi,

I am trying to use a managed dialog. I noticed that after the first time I display it, subsequent creations don't actually make a new instance of the dialog, they just seem to reuse the first one.

If I want to stop that, and get a brand new instance on every call, is this the right way to do it?:

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case MY_DIALOG_ID:
            MyDlg dlg = new MyDlg(this);
            dlg.setOnDismissListener(new OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    removeDialog(MY_DIALOG_ID);
                }
            });
            return dlg;
    }
    return null;
}

so I guess the removeDialog() call does the trick, but my onDismiss() handler should be called in every instance of the dialog being killed, right (like Dialog.cancel(), Dialog.dismiss(), hitting the back key)?

Thanks

+1  A: 

Hi!
As you noticed, onCreateDialog() method is called only for the very first time you show the dialog. It's responsible for constructing the dialog. Truth is you don't have to "destroy" your dialog to force onCreateDialog to be called each time when you want to show your dialog. You can override onPrepareDialog(int, Dialog) - this one is called just before dialog is going to be displayed. (it can recycle dialog constructed in previous onCreateDialog call) "Define this method if you want to change any properties of the dialog each time it is opened."
Regards!

Ramps