Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to navigate to the "Profile" screen when the button is clicked.
Android Kotlin
Button(onClick = { navController.[1]("profile") }) {
Text("Go to Profile")
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using popBackStack() which goes back instead of forward.
Using start() which is not a NavController function.
✗ Incorrect
The navigate() function is used to move to another composable screen by specifying its route.
2fill in blank
mediumComplete the code to define a NavHost with a start destination of "home".
Android Kotlin
NavHost(navController = navController, startDestination = "[1]") { composable("home") { HomeScreen() } composable("profile") { ProfileScreen() } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting startDestination to a route not defined in NavHost.
Using a route name that does not match any composable.
✗ Incorrect
The startDestination should be set to "home" to show the HomeScreen first.
3fill in blank
hardFix the error in the code to pop back to the previous screen correctly.
Android Kotlin
navController.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like navigateBack or goBack.
Trying to use back() which is not a NavController method.
✗ Incorrect
popBackStack() is the correct function to go back to the previous composable screen.
4fill in blank
hardFill both blanks to navigate to "details" screen with an argument "itemId".
Android Kotlin
navController.navigate("details/$[1]") { launchSingleTop = [2] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong argument name in the route string.
Setting launchSingleTop to false causing multiple instances.
✗ Incorrect
The route needs the argument name 'itemId' and launchSingleTop should be true to avoid multiple copies.
5fill in blank
hardFill all three blanks to define a composable with a route that accepts a "userId" argument of type String.
Android Kotlin
composable(route = "user/[1]", arguments = listOf(navArgument("[2]") { type = [3] })) { UserScreen() }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for route and argument.
Using NavType.IntType for a string argument.
✗ Incorrect
The route and argument name must match 'userId' and the argument type is NavType.StringType for strings.