Challenge - 5 Problems
Navigation Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when you call navigate() on NavController?
Given a NavController instance, what is the immediate effect of calling
navController.navigate(R.id.destinationFragment) in an Android app?Android Kotlin
navController.navigate(R.id.destinationFragment)
Attempts:
2 left
💡 Hint
Think about what navigation means in a single-activity app using fragments.
✗ Incorrect
Calling navigate() on NavController changes the visible fragment to the specified destination and adds this transaction to the back stack, allowing the user to return.
❓ lifecycle
intermediate2:00remaining
When is NavHostFragment created in the activity lifecycle?
In an Android app using Navigation Component, at which point in the activity lifecycle is the NavHostFragment typically created and attached?
Attempts:
2 left
💡 Hint
Think about when views are created from XML layouts.
✗ Incorrect
NavHostFragment is part of the activity's layout and is created when setContentView() inflates the layout during onCreate().
📝 Syntax
advanced2:00remaining
Identify the correct way to obtain NavController in a fragment
Which Kotlin code snippet correctly obtains the NavController inside a fragment?
Attempts:
2 left
💡 Hint
Remember the extension function available in fragments.
✗ Incorrect
In a fragment, the extension function findNavController() is the recommended way to get the NavController instance.
🔧 Debug
advanced2:00remaining
Why does navigation crash with IllegalArgumentException?
You call
navController.navigate(R.id.action_to_unknown) but the app crashes with IllegalArgumentException: navigation destination unknown. What is the most likely cause?Android Kotlin
navController.navigate(R.id.action_to_unknown)
Attempts:
2 left
💡 Hint
Check your navigation graph XML for the destination ID.
✗ Incorrect
The error means the navigation graph does not contain a destination with the given ID, so navigation cannot proceed.
🧠 Conceptual
expert3:00remaining
How does NavHostFragment manage back stack differently than FragmentManager?
What is a key difference in how NavHostFragment manages the back stack compared to directly using FragmentManager transactions?
Attempts:
2 left
💡 Hint
Think about the role of the navigation graph in Navigation Component.
✗ Incorrect
NavHostFragment uses the navigation graph to define all possible destinations and manages the back stack automatically, simplifying navigation compared to manual FragmentManager transactions.