I had a similar problem, but I wanted to report another action about turning off the dialog (and not about the activity that created and displayed the dialog).
Although you can simply override the onDismiss() method in your dialog mode, as suggested by Austyn Mahoney, you cannot use setOnDismissListener() because DialogFragment simply does not provide such a method (according to: Android Developers Dialog Reference ).
But still there is another good way to inform any other activity about turning off the dialog , (I found it there: DialogFragment and onDismiss ), here it is:
First, you must do your action (the one that you want to convey information about turning off the dialog) to implement OnDismissListener :
public final class YourActivity extends Activity implements DialogInterface.OnDismissListener { @Override public void onDismiss(final DialogInterface dialog) {
Again, according to the Android Developers Dialog Interface Reference, DialogFragment already implements OnDismissListener using the onDismiss() method. This is why you should override it and call your onDismiss() method there, which you implemented in YourActivity:
public final class DialogFragmentImage extends DialogFragment { @Override public void onDismiss(final DialogInterface dialog) { super.onDismiss(dialog); final Activity activity = getActivity(); if (activity instanceof DialogInterface.OnDismissListener) { ((DialogInterface.OnDismissListener) activity).onDismiss(dialog); } } }
source share