捕获 BottomSheetDialogFragment 的解雇

Catch dismissal of BottomSheetDialogFragment

有什么方法可以捕获 BottomSheetDialogFragment 的 dismissal/cancel 吗?

底部sheetclass

public class ContactDetailFragment extends BottomSheetDialogFragment
{
    private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback()
    {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState)
        {
            if (newState == BottomSheetBehavior.STATE_HIDDEN)
            {
                dismiss();
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset)
        {
        }
    };

    @Override
    public void setupDialog(Dialog dialog, int style)
    {
        super.setupDialog(dialog, style);
        View contentView = View.inflate(getContext(), R.layout.fragment_contactdetail, null);

        dialog.setContentView(contentView);

        BottomSheetBehavior mBottomSheetBehavior = BottomSheetBehavior.from(((View) contentView.getParent()));
        if (mBottomSheetBehavior != null)
        {
            mBottomSheetBehavior.setBottomSheetCallback(mBottomSheetBehaviorCallback);
            mBottomSheetBehavior.setPeekHeight((int) DisplayUtils.dpToPixels(CONTACT_DETAIL_PEEK_HEIGHT, getResources().getDisplayMetrics()));
        }
    }
}

我试过的方法都不行

鉴于它本质上是一个对话片段,必须有某种方法来捕捉解雇?

找到一个简单的解决方案。 在 BottomSheetDialogFragment 中使用 onDestroyonDetach 可以让我正确地解雇