0
0
Android Kotlinmobile~10 mins

Nested navigation graphs in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a NavHostFragment in the activity layout.

Android Kotlin
val navHostFragment = supportFragmentManager.findFragmentById(R.id.[1]) as NavHostFragment
Drag options to blanks, or click blank then click option'
Anav_host_fragment
Bmain_nav_host
Cnav_graph_host
Dfragment_container
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect fragment ID that does not exist in the layout.
Confusing the NavHostFragment ID with other container IDs.
2fill in blank
medium

Complete the code to navigate to a nested graph destination using NavController.

Android Kotlin
navController.navigate(R.id.[1])
Drag options to blanks, or click blank then click option'
AprofileFragment
BhomeFragment
Cnested_graph
DsettingsFragment
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to navigate directly to a fragment inside the nested graph without specifying the nested graph ID.
Using a fragment ID instead of the nested graph ID.
3fill in blank
hard

Fix the error in the nested graph XML by completing the missing attribute.

Android Kotlin
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/[1]"
    app:startDestination="homeFragment">
Drag options to blanks, or click blank then click option'
Amain_graph
Bapp_nav_graph
Croot_graph
Dnested_graph
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same ID as the main graph causing conflicts.
Omitting the android:id attribute entirely.
4fill in blank
hard

Fill both blanks to define a nested navigation graph with a start destination.

Android Kotlin
<navigation android:id="@+id/[1]" app:startDestination="[2]">
Drag options to blanks, or click blank then click option'
Anested_graph
BhomeFragment
CprofileFragment
Dmain_graph
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the graph ID with fragment IDs.
Setting a start destination that does not exist in the nested graph.
5fill in blank
hard

Fill all three blanks to correctly retrieve the NavController from a nested NavHostFragment.

Android Kotlin
val navHostFragment = supportFragmentManager.findFragmentById(R.id.[1]) as [2]
val navController = navHostFragment.[3]
Drag options to blanks, or click blank then click option'
Anested_nav_host
BNavHostFragment
CnavController
Dmain_nav_host
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong fragment ID.
Casting to the wrong fragment type.
Trying to access navController without casting.