Karen Frangulyan
10/26/2025, 12:17 AMBackHandler in CMP now. But how can I call the back press handler manually, for example, on a button click?
On Android I can simply use LocalOnBackPressedDispatcherOwner.current and I can be sure that the correct back press logic will work, like calling a BackHandler if someone installed it, or falling back to nav controller if not (I’m on Nav2). Is there something similar in CMP?Vilgot Fredenberg
10/27/2025, 9:04 AMnavigationevent and use LocalNavigationEventDispatcherOwner. I've created a helper function and then call DirectNavigationEventInput::backCompleted to go back.
@Composable
fun rememberNavigationEventInput(): DirectNavigationEventInput {
val input = remember { DirectNavigationEventInput() }
LocalNavigationEventDispatcherOwner.current?.navigationEventDispatcher?.let { dispatcher ->
DisposableEffect(dispatcher) {
dispatcher.addInput(input)
onDispose { dispatcher.removeInput(input) }
}
}
return input
}Karen Frangulyan
10/27/2025, 12:56 PMVilgot Fredenberg
10/27/2025, 1:03 PMLocalOnBackPressedDispatcherOwner, for example, just forwards stuff to LocalNavigationEventDispatcherOwner. Briefly looking through compose-multiplatform-core, I can see a lot of references to it as well.
• It should be set up by compose for you (ComponentActivity in the case of Android) and you should therefore already (transitively) depend upon it