How to know if a dialog is dismissed in Android?

Marshal Chen picture Marshal Chen · Jul 9, 2013 · Viewed 22.9k times · Source

If the dialog is dismissed,I want to do something for my background.So I want to know if the dialog is dismissed

Answer

Ken Wolf picture Ken Wolf · Jul 9, 2013

You can use an onDismissListener

http://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html

public Dialog createDialog() {
    Dialog d = new Dialog(this);
    d.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(final DialogInterface arg0) {
            // do something
        }
    });
    return d;
}

If you are using a DialogFragment just override onDismiss()

http://developer.android.com/reference/android/app/DialogFragment.html#onDismiss(android.content.DialogInterface)