iex
03/24/2020, 1:54 PMfun Fragment.onBack(consume: Boolean = false, callback: () -> Unit) {
activity?.onBackPressedDispatcher?.addCallback {
callback()
if (!consume) {
findNavController().navigateUp()
}
}
}
Works perfectly when I don't want to consume the event. It also works when I consume it, except that after it the back button is dead. How do I consume only the current back press?Adam Powell
03/24/2020, 2:23 PMAdam Powell
03/24/2020, 2:28 PMaddCallback
that accepts a LifecycleOwner
to manage the callback automatically for youiex
03/24/2020, 2:37 PMiex
03/24/2020, 2:37 PMAdam Powell
03/24/2020, 2:40 PM.remove()
methodAdam Powell
03/24/2020, 2:41 PMaddCallback
iex
03/25/2020, 1:53 PMiex
03/25/2020, 1:53 PMiex
04/03/2020, 9:51 AMLifecycleOwner
the issues are fixed. It's weird, since I remember having tried this out but probably I was doing something else wrong then.