Challenge - 5 Problems
Nested Navigation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
intermediate
2:00remaining
Identify the start destination in nested navigation graphs
Given the nested navigation graph below, which fragment will be shown first when the app starts?
Android Kotlin
val navGraph = navController.navInflater.inflate(R.navigation.main_nav_graph).apply {
startDestination = R.id.home_nav_graph
}
val homeNavGraph = navController.navInflater.inflate(R.navigation.home_nav_graph).apply {
startDestination = R.id.dashboardFragment
}
val settingsNavGraph = navController.navInflater.inflate(R.navigation.settings_nav_graph).apply {
startDestination = R.id.settingsFragment
}Attempts:
2 left
💡 Hint
The start destination of the main graph points to a nested graph, which itself has a start destination fragment.
✗ Incorrect
The main navigation graph's start destination is the home_nav_graph nested graph. Inside home_nav_graph, the start destination is dashboardFragment, so that fragment is shown first.
❓ ui_behavior
intermediate2:00remaining
Effect of nested graph on back button behavior
In an app with nested navigation graphs, what happens when the user presses the back button on a fragment inside a nested graph?
Attempts:
2 left
💡 Hint
Think about how navigation stacks work with nested graphs.
✗ Incorrect
The back button navigates back through the nested graph's stack first. Once at the nested graph's start destination, pressing back moves to the parent graph's previous destination or exits if none.
❓ lifecycle
advanced2:30remaining
Lifecycle impact of nested navigation graphs on fragments
When navigating from a fragment in one nested graph to a fragment in another nested graph, what happens to the lifecycle of the first fragment?
Attempts:
2 left
💡 Hint
Consider how fragment lifecycle works with navigation and back stack.
✗ Incorrect
Navigating away triggers onPause and onStop for the first fragment, but it stays in memory on the back stack until popped or replaced.
📝 Syntax
advanced2:00remaining
Correct Kotlin code to navigate between nested graphs
Which Kotlin code snippet correctly navigates from a fragment in one nested graph to a fragment in another nested graph using Navigation Component?
Android Kotlin
navController.navigate(R.id.action_currentGraphFragment_to_targetGraphFragment)
Attempts:
2 left
💡 Hint
Use the generated action ID for navigation between fragments.
✗ Incorrect
Navigation between fragments in nested graphs requires using the action ID defined in the navigation XML, not just the destination ID or string.
🔧 Debug
expert3:00remaining
Diagnose navigation crash due to nested graph misconfiguration
An app crashes with IllegalArgumentException: Navigation destination R.id.profileFragment is unknown to this NavController. The profileFragment is inside a nested graph. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check if all nested graphs are properly referenced in the main graph.
✗ Incorrect
If a nested graph is not included in the main graph, its destinations are unknown to the NavController, causing this crash.