Qamar A. Safadi
08/06/2023, 6:11 AMRafs
08/06/2023, 9:16 AMQamar A. Safadi
08/06/2023, 9:17 AMQamar A. Safadi
08/06/2023, 9:17 AMRafs
08/06/2023, 9:21 AMonBackPressed
in your activity, you should call super.onBackPressed
at the end.Qamar A. Safadi
08/06/2023, 9:22 AMRafs
08/06/2023, 9:23 AMRafs
08/06/2023, 9:43 AMBackPressedDispatcher
in one of your fragments, you'll have to either disable the dispatcher or make a further call to the activity's onBackPressed
to propagate the event to other observers in the chain.
This could be your fragment's onAttach
method;
override fun onAttach(context: Context) {
super.onAttach(context)
requireActivity().onBackPressedDispatcher
.addCallback(
owner = this,
enabled = true // set this to false
) {
Log.d("Test", "onBackPressed: handled by fragment!")
requireActivity().onBackPressed() // or call the activity's onBackPressed
}
}