Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomSheetDialogFragment keeps reappearing at onResume

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.

like image 849
Battlestr1k3 Avatar asked Sep 12 '25 06:09

Battlestr1k3


2 Answers

(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....
                }
            });
like image 92
halfer Avatar answered Sep 14 '25 21:09

halfer


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

        }
like image 21
Mahmoud Mabrok Avatar answered Sep 14 '25 19:09

Mahmoud Mabrok