0
0
Android Kotlinmobile~10 mins

Navigating between composables in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Alaunch
Bnavigate
Cstart
DpopBackStack
Attempts:
3 left
💡 Hint
Common Mistakes
Using popBackStack() which goes back instead of forward.
Using start() which is not a NavController function.
2fill in blank
medium

Complete 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'
Ahome
Bprofile
Cdashboard
Dmain
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.
3fill in blank
hard

Fix 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'
Aback
BnavigateBack
CgoBack
DpopBackStack
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like navigateBack or goBack.
Trying to use back() which is not a NavController method.
4fill in blank
hard

Fill 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'
AitemId
Btrue
Cfalse
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong argument name in the route string.
Setting launchSingleTop to false causing multiple instances.
5fill in blank
hard

Fill 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'
AuserId
CNavType.StringType
DNavType.IntType
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for route and argument.
Using NavType.IntType for a string argument.