Your First Kotlin Android App: Polishing the App

Aug 22 2023 · Kotlin 1.8.20, Android 13, Android Studio Flamingo | 2022.2.1

Part 3: Finish the App

20. Add Navigation to the App

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 19. Create an About Page Next episode: 21. Challenge: Implement the Back Button

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Navigation in Jetpack Compose refers to the interactions that lets you move across composables in your app. And this is possible using the Navigation components API which is bundled with cool features to make handling navigation easier.

implementation('androidx.navigation:navigation-compose:2.5.3')
@Composable
fun MainScreen() {

}
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
  MainScreen() // Update Code
}
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "gamescreen") {
  composable("gamescreen") { GameScreen() }
  composable("about") { AboutScreen() }
}
@Composable
fun GameDetail(
  //...
  onNavigateToAbout: () -> Unit // New Code
) {
onClick = { onNavigateToAbout() },
GameDetail(onStartOver = {}, onNavigateToAbout = {})
GameDetail(
  //...
  onNavigateToAbout = onNavigateToAbout,
  //...
)
fun GameScreen(
  onNavigateToAbout: () -> Unit
) {
  //...
}
GameScreen(onNavigateToAbout = {})
composable("gamescreen") {
  GameScreen(
    onNavigateToAbout = { navController.navigate("about") } // New Code
  )
}