https://kotlinlang.org logo
Title
e

Erlan Amanatov

02/14/2022, 12:36 PM
Hi, I want to navigate to a new screen and clear the back stack. Am I doing it in a right way? Code in 🧵
1
NavHost(
    navController = navController,
    route = "nav_host",
    startDestination = startDestination
) {...}
and later
navController.navigate(TargetScreen){
    popUpTo("nav_host")
}
i

Ian Lake

02/14/2022, 11:57 PM
You shouldn't be popping your start destination off the back stack at all as per the Principles of Navigation: https://developer.android.com/guide/navigation/navigation-principles#fixed_start_destination
Can you explain what you're trying to do?
e

Erlan Amanatov

02/15/2022, 1:31 PM
@Ian Lake At the start destination, I'm checking the current user because the next screen depends on the user's role. I want to navigate to that start destination later only on <Logout> event.
i

Ian Lake

02/15/2022, 5:27 PM
That page also talks about how login should never be your start destination, a topic we've talked about here a number of times: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1617812338353700?thread_ts=1617805109.343700&amp;cid=CJLTWPH7S
e

Erlan Amanatov

02/15/2022, 6:14 PM
Login is not a start destination in the scheme
f

Francesc

02/15/2022, 8:11 PM
trying to get some clarity - why can't you navigate to the start destination while popping all other screens from the stack? Also, your screenshot reads "close app on backpress" - if you want to close the app, you can call
finish
on your activity