Challenge - 5 Problems
Navigation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Navigation Graph XML Structure
Which option correctly defines a navigation graph XML with two fragments named HomeFragment and DetailFragment?
Attempts:
2 left
💡 Hint
Remember to include both xmlns attributes and set the startDestination with the correct fragment id.
✗ Incorrect
Option D correctly uses the tag with both xmlns:android and xmlns:app namespaces, sets the startDestination attribute, and defines fragments with proper ids and names. Other options miss namespaces, use wrong tags, or omit the startDestination.
📝 Syntax
intermediate2:00remaining
Correct Kotlin Code to Navigate Between Fragments
Which Kotlin code snippet correctly navigates from HomeFragment to DetailFragment using Navigation component?
Android Kotlin
class HomeFragment : Fragment(R.layout.fragment_home) {
fun goToDetail() {
// navigation code here
}
}Attempts:
2 left
💡 Hint
Use the fragment's extension function to get NavController and navigate using the action id.
✗ Incorrect
Option A uses the fragment's findNavController() extension and navigates using the correct action id. Option A is invalid because 'this' in fragment is not a View. Option A uses a destination id instead of action id, which may not work. Option A uses an undefined navController variable.
❓ lifecycle
advanced2:00remaining
Navigation Component and Fragment Lifecycle
What happens to the previous fragment's view when navigating to a new fragment using Navigation component with default settings?
Attempts:
2 left
💡 Hint
Think about how Navigation component manages fragment views by default to save memory.
✗ Incorrect
By default, Navigation component replaces the current fragment's view and destroys it to free resources. The fragment instance is also destroyed unless added to back stack. Other options describe behaviors not default in Navigation component.
🔧 Debug
advanced2:00remaining
Fixing Navigation Crash on Button Click
Given this Kotlin code inside a fragment, the app crashes when the button is clicked. What is the cause?
Android Kotlin
button.setOnClickListener {
Navigation.findNavController(requireActivity()).navigate(R.id.action_homeFragment_to_detailFragment)
}Attempts:
2 left
💡 Hint
Check the parameter passed to findNavController to ensure it is a View inside a NavHostFragment.
✗ Incorrect
Navigation.findNavController expects a View that is inside a NavHostFragment. Passing requireActivity() causes a crash because it's not a View. The correct approach is to pass the button view or use findNavController() extension on fragment.
🧠 Conceptual
expert2:00remaining
Deep Link Handling in Navigation Component
Which statement about deep link handling in Navigation component is true?
Attempts:
2 left
💡 Hint
Think about how Navigation component integrates with Android's intent system.
✗ Incorrect
Navigation component supports deep links declared in the navigation graph XML. When a deep link is triggered, the component automatically navigates to the destination. Manual intent handling is not required. Deep links work even if the app is not running.