I show a BottomSheetDialogFragment with the following code:
BottomSheetDialogFragment bottomSheetDialogFragment = new MediaAddFragment();
bottomSheetDialogFragment.show(getActivity().getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
getActivity().getSupportFragmentManager().executePendingTransactions();
bottomSheetDialogFragment.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
onResume();
MainActivity.updateMediaButtons();
}
});
To close it, I call dismiss() from within the Fragment. With that, it gets dismissed, but is shown again if the app gets resumed, which is not my intention.
I would be glad if someone could help me with this. I already scanned various tutorials on how to properly use those BottomSheetDialogFragments, but I cannot find my error.
Incidentally, I don't have any code in onResume to test it.
(Posted on behalf of the OP).
I found my error, I was overwriting the onDismissListener of the BottomSheetDialogFragment in the calling fragment. Now it works as expected.
bottomSheetDialogFragment2.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
// Adding the following line fixed the problem for me
bottomSheetDialogFragment2.onDismiss(dialog);
// some Code....
}
});
I have faced this issue from 15 minutes and issue was that i did not call onDismiss
of BottomSheet:
override fun onDismiss(dialog: DialogInterface) {
if (shouldDismiss)
onDismiss.invoke()
}
So in your code it should be:
@Override
public void onDismiss(DialogInterface dialog) {
onResume();
MainActivity.updateMediaButtons();
super.onDismiss(dialog); // add this line
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With