In my application I have a fragment which open a dialog fragment. In my dialog fragment I take in input from user some settings that in save in a static class, but I need a listener to inform my Fragment that the dialog was closed.
I use the code from the first answer of this link stackoverflow question but this part of code doesn't work because I have a fragment and not an activity. The onDismiss method is called in dialogfragment but the if statement fails and so doesn't call the fragment. I tried to replace that part with getFragmentManager and with getParentFragment and get/setTargetFragment but doesn't work.
Someone can help me please?
public void onDismiss(final DialogInterface dialog) {
super.onDismiss(dialog);
// code I've tried
final FragmentManager fragment = getFragmentManager();
if (fragment instanceof DialogInterface.OnDismissListener) {
((DialogInterface.OnDismissListener) fragment).onDismiss(dialog);
}
// original answer code
/*final Activity activity = getActivity();
if (activity instanceof DialogInterface.OnDismissListener) {
((DialogInterface.OnDismissListener) activity).onDismiss(dialog);
}*/
}