NavController is an object that manages app navigation within Compose. It keeps track of the back stack and lets you move between composables (screens).
Click to reveal answer
beginner
How do you define a navigation graph in Compose?
You use the NavHost composable with a NavController and define composable destinations inside it using composable() functions.
Click to reveal answer
beginner
What does the navigate() function do?
It tells the NavController to move to a different composable screen by specifying the route name.
Click to reveal answer
intermediate
How can you pass data between composables during navigation?
You can include parameters in the route string and retrieve them in the destination composable using NavBackStackEntry arguments.
Click to reveal answer
beginner
Why is it important to handle the back stack in navigation?
Handling the back stack ensures users can go back to previous screens naturally, like pressing the device back button, improving user experience.
Click to reveal answer
Which composable is used to set up navigation destinations in Jetpack Compose?
ANavHost
BNavController
CNavGraphBuilder
DNavDestination
✗ Incorrect
NavHost is the composable that hosts navigation destinations and connects them with the NavController.
How do you trigger navigation to another screen?
AUse a FragmentTransaction
BUse setContent() again
CCall startActivity()
DCall navigate() on NavController with the route
✗ Incorrect
In Compose navigation, you call navigate() on the NavController with the destination route.
What is the purpose of the back stack in navigation?
ATo store user data
BTo keep track of navigation history
CTo load images faster
DTo manage network calls
✗ Incorrect
The back stack keeps track of the order of screens visited so users can go back.
How can you pass a user ID to a detail screen in Compose navigation?
AStore it in SharedPreferences
BUse a global variable
CInclude it as a parameter in the route string
DUse a database query
✗ Incorrect
Passing parameters in the route string is the recommended way to send data between composables.
Which of these is NOT part of Compose navigation?
AFragmentManager
BNavHost
CNavController
Dcomposable() destination
✗ Incorrect
FragmentManager is used in traditional Android views, not in Compose navigation.
Explain how navigation works between composables in Jetpack Compose.
Think about how you move from one screen to another and how the app remembers where you were.
You got /4 concepts.
Describe how to pass data when navigating from one composable to another.
Consider how you might send a message or ID along with the navigation action.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of NavController in Jetpack Compose navigation?
easy
A. To create UI elements inside a composable
B. To handle database operations
C. To manage navigation between composable screens
D. To style composables with themes
Solution
Step 1: Understand the role of NavController
NavController is responsible for controlling navigation actions between composables in an app.
Step 2: Differentiate from other components
It does not create UI elements, handle databases, or style components; those are handled by other parts of Compose or Android.
Final Answer:
To manage navigation between composable screens -> Option C
Quick Check:
NavController manages navigation [OK]
Hint: NavController controls screen changes in Compose [OK]
Common Mistakes:
Confusing NavController with UI creation
Thinking NavController handles data or styling
Mixing NavController with ViewModel
2. Which of the following is the correct syntax to navigate to a composable with route "profile" using NavController named navController?
easy
A. navController.navigate("profile")
B. navController.goTo("profile")
C. navController.move("profile")
D. navController.open("profile")
Solution
Step 1: Recall the navigation method
The correct method to navigate is navigate() on NavController.
Step 2: Check method names
Only navigate() is valid; others like goTo(), move(), or open() do not exist.
Final Answer:
navController.navigate("profile") -> Option A
Quick Check:
Use navigate() to change screens [OK]
Hint: Use navigate() method on NavController [OK]
Common Mistakes:
Using non-existent methods like goTo or move
Forgetting to pass route as a string
Calling navigation on wrong object
3. Given this code snippet inside a composable:
val navController = rememberNavController()
Button(onClick = { navController.navigate("details") }) {
Text("Go to Details")
}
What happens when the button is clicked?
medium
A. The app navigates to the composable with route "details"
B. The app closes immediately
C. Nothing happens because navigate() is incorrect
D. The app crashes due to missing NavHost
Solution
Step 1: Understand the button's onClick action
The button calls navController.navigate("details") which triggers navigation to the "details" route.
Step 2: Consider NavHost presence
Assuming NavHost is set up correctly with "details" route, navigation will succeed and show that screen.
Final Answer:
The app navigates to the composable with route "details" -> Option A
Quick Check:
Button triggers navigate() to details [OK]
Hint: Button click calls navigate() to change screen [OK]
5. You want to navigate from a composable "list" to "details/{itemId}" passing an item ID as argument. Which code correctly navigates to details screen with itemId = 42?
hard
A. navController.navigate("details/{itemId}")
B. navController.navigate("details")
C. navController.navigate("details?itemId=42")
D. navController.navigate("details/42")
Solution
Step 1: Understand route parameter usage
When route has a placeholder like "details/{itemId}", you replace {itemId} with actual value in the route string.
Step 2: Check each option
navController.navigate("details/42") correctly replaces {itemId} with 42. navController.navigate("details") misses the parameter. navController.navigate("details?itemId=42") uses query syntax which is not standard here. navController.navigate("details/{itemId}") uses the placeholder literally, which won't work.
Final Answer:
navController.navigate("details/42") -> Option D
Quick Check:
Replace {itemId} with actual value in route [OK]
Hint: Replace placeholders with actual values in route string [OK]
Common Mistakes:
Passing route with placeholder instead of value
Using query parameters incorrectly
Omitting required route arguments
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.