how to handle onbackpressed in fragment
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner){
YOU CODE !!
}
how to handle onbackpressed in fragment
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner){
YOU CODE !!
}
onBackPressed() in fragment
activity?.onBackPressedDispatcher?.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
}
})
on back press in fragment
//You need to add the following line for this solution to work; thanks skayred
fragment.getView().setFocusableInTouchMode(true);
fragment.getView().requestFocus();
fragment.getView().setOnKeyListener( new OnKeyListener()
{
@Override
public boolean onKey( View v, int keyCode, KeyEvent event )
{
if( keyCode == KeyEvent.KEYCODE_BACK )
{
return true;
}
return false;
}
} );
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us