2

I want to do some data checking after dialog.dismiss() or dialog.cancel is called.

How should I go about doing this?

Are there any overrides, Listener or methods that i can implement to do some action then dismiss the Dialog?

I tried dialog.setOnDismissListener but that dismisses the dialog first then calls this listener.

Mysterious_android
  • 586
  • 1
  • 8
  • 30

2 Answers2

5

You could create your own custom Dialog with a DialogFragment and just overwrite dismiss().

public class CustomDialog extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Build the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.dialog_fire_missiles);
        return builder.create();
    }

    @Override
    public void dismiss() {
        // Do your stuff here
        super.dismiss();
    }

    ...
}

Take a look here https://developer.android.com/guide/topics/ui/dialogs.html

mbo
  • 4,421
  • 1
  • 31
  • 53
  • For me this still doesn't work, when I arrive in Dismiss the dialog is already dismissed even before super.dismiss(); NB: I am using Xamarin – Guillaume Martin Dec 18 '19 at 16:32
1

Just press alt+insrt select option override method and choose method name that you want to override.

Thank you

Rhn Bhadani
  • 2,208
  • 1
  • 17
  • 25