I have a Bottom Sheet Dialog Fragment
which contains four Fragment
with ViewPager
.
I want to call a method when onBackPressed
clicked in Bottom Sheet Dialog Fragment
. Implemented OnBackPressedCallback
in my OnCreateView
but it is not triggered. Any one have a idea why it is not called?
val callback = object : OnBackPressedCallback(true */ true means that the callback is enabled /*) {
override fun handleOnBackPressed() {
// Show your dialog and handle navigation
LogUtils.d("Bottom Sheet -> Fragment BackPressed Invoked")
}
}
// note that you could enable/disable the callback here as well by setting callback.isEnabled = true/false
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
onActivityCreated()
. Also try usingthis
instead ofviewLifecycleOwner
– FazioDialogFrament
but it works in a normalFragment
. Were you able to resolve it @Donata – Chancemedley