0
0
Android Kotlinmobile~20 mins

Nested navigation graphs in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Navigation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
navigation
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
}
Amain_nav_graph
BsettingsFragment
Chome_nav_graph
DdashboardFragment
Attempts:
2 left
💡 Hint
The start destination of the main graph points to a nested graph, which itself has a start destination fragment.
ui_behavior
intermediate
2: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?
AThe app navigates back within the nested graph until its start destination, then back to the parent graph.
BThe back button is disabled inside nested graphs.
CThe app skips the nested graph and goes directly to the main graph's start destination.
DThe app immediately exits regardless of navigation stack.
Attempts:
2 left
💡 Hint
Think about how navigation stacks work with nested graphs.
lifecycle
advanced
2: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?
AThe first fragment's onPause and onStop are called, but it remains in memory until popped from back stack.
BThe first fragment is immediately destroyed and removed from memory.
CThe first fragment remains fully active and visible behind the new fragment.
DThe first fragment's lifecycle methods are not called until the app is closed.
Attempts:
2 left
💡 Hint
Consider how fragment lifecycle works with navigation and back stack.
📝 Syntax
advanced
2: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)
AnavController.navigate("targetGraphFragment")
BnavController.navigate(R.id.action_currentGraphFragment_to_targetGraphFragment)
CnavController.navigate(R.id.targetGraphFragment)
DnavController.navigate(R.navigation.targetGraphFragment)
Attempts:
2 left
💡 Hint
Use the generated action ID for navigation between fragments.
🔧 Debug
expert
3: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?
AThe profileFragment ID is duplicated in multiple graphs causing conflict.
BThe NavController was not initialized before navigation call.
CThe nested graph containing profileFragment is not included or linked in the main navigation graph.
DThe profileFragment class is missing from the project source code.
Attempts:
2 left
💡 Hint
Check if all nested graphs are properly referenced in the main graph.