I have customized back button. when I click on it, the application crashes after a second. here is the code:
it looks for active callbacks and if found any calls them and returns. that's what makes the loop.
your code should be:
isEnabled = false
requireActivity().onBackPressedDispatcher.onBackPressed()
CodePudding user response:
replace
requireActivity().onBackPressedDispatcher.onBackPressed()
with just
finish()
currently your onBackPressedDispatcher
set in Fragment
is calling onBackPressed
in (require
d Activity
), which will at first try to propagate this event to own childrens - Fragment
s. so, again, onBackPressedDispatcher
will be triggered, again it will call Activity
s method and this is loop
edit: isEnabled = false
is a better approach, just wanted to leave you some case description