https://kotlinlang.org logo
#android
Title
# android
b

bryankeltonadams

06/19/2023, 11:24 PM
Fixed Start Destination question. 🧵
not kotlin but kotlin colored 4
Fixed start destination Every app you build has a fixed start destination. This is the first screen the user sees when they launch your app from the launcher. This destination is also the last screen the user sees when they return to the launcher after pressing the Back button. Let’s take a look at the Sunflower app as an example. https://developer.android.com/guide/navigation/principles Based on this statement in the Android Navigation Principles. Is it not recommended to allow something such as, remembering which "Section/Tab/Module" the user was in last before closing the app out, and using that as the startDestination when opening the app? Or can we still do something like that by setting the startDestination to not necessarily the last spot the user was at last, but then immediately navigating to somewhere else based on a startDestination value set in AppState or something?
i

Ian Lake

06/20/2023, 3:22 AM
See the guide which specifically talks about this pattern (setting a start destination based on a user preference - FWIW, you'd never want to set it via "last remembered since that leads to unpredictable behavior, particularly when you take into account deep linking and user's memory being finite. That's the whole point of it being fixed - to be predictable): https://developer.android.com/guide/navigation/use-graph/programmatic#modify_inflated
🙌 1
b

bryankeltonadams

06/20/2023, 4:37 PM
@Ian Lake I'm using Jetpack Compose, would an equivalent of this just to be to navigate with the navController? Or is there a different way to get a reference to the NavGraph and change the start destination??
i

Ian Lake

06/20/2023, 6:11 PM
You would not add the NavHost to composition until you know what your start destination to be
🙌 1