-
|
I think I have everything setup correctly, yet when I push back button the app closed (goes to main android screen) instead of going back in stack (and there are items in stack). In the root component I have: private val router = StackNavigation<Configuration>()
override val routerState = childStack(
source = router,
serializer = Configuration.serializer(),
initialConfiguration = Configuration.Roster,
handleBackButton = true,
childFactory = ::createChild,
)Then during navigation I use On each navigation (and push) I see in the logs that the items are correctly added to the stack: I would assume that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
|
|
Beta Was this translation helpful? Give feedback.
That's because the root
ComponentContextbeing created asDefaultComponentContext(lifecycle = lifecycle)is disconnected from the Activity'sOnBackPressedDispatcher, meaning the Activity is not aware of its internal back stack and just closes when the back is pressed.The
defaultComponentContext()is an extension function that automatically connectsLifecycle,StateKeeper,InstanceKeeperandBackHandlerto the hosting Activity. Without it you'd need to manually drive the lifecycle, plus state preservation, instance retaining and back handling won't work.