0
0
Android Kotlinmobile~10 mins

Navigation component setup 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 set up the NavController in an Activity.

Android Kotlin
val navController = findNavController([1])
Drag options to blanks, or click blank then click option'
Athis
BR.layout.activity_main
CsupportFragmentManager
DR.id.nav_host_fragment
Attempts:
3 left
💡 Hint
Common Mistakes
Using layout resource ID instead of fragment ID.
Passing the Activity context instead of fragment ID.
2fill in blank
medium

Complete the code to navigate to the destination fragment using NavController.

Android Kotlin
navController.[1](R.id.destinationFragment)
Drag options to blanks, or click blank then click option'
Anavigate
BpopBackStack
CsetGraph
DaddOnDestinationChangedListener
Attempts:
3 left
💡 Hint
Common Mistakes
Using popBackStack to go forward.
Trying to set the graph instead of navigating.
3fill in blank
hard

Fix the error in the code to correctly set up the NavHostFragment in the Activity's layout.

Android Kotlin
<fragment
    android:id="@+id/nav_host_fragment"
    android:name="[1]"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:navGraph="@navigation/nav_graph"
    app:defaultNavHost="true" />
Drag options to blanks, or click blank then click option'
Aandroidx.navigation.NavController
Bandroidx.fragment.app.Fragment
Candroidx.navigation.fragment.NavHostFragment
Dandroidx.navigation.NavGraph
Attempts:
3 left
💡 Hint
Common Mistakes
Using Fragment or NavController instead of NavHostFragment.
Omitting the android:name attribute.
4fill in blank
hard

Fill both blanks to create a NavOptions object that animates navigation transitions.

Android Kotlin
val options = NavOptions.Builder()
    .setEnterAnim([1])
    .setExitAnim([2])
    .build()
Drag options to blanks, or click blank then click option'
AR.anim.slide_in_right
BR.anim.fade_out
CR.anim.slide_out_left
DR.anim.fade_in
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing fade and slide animations incorrectly.
Using the same animation for enter and exit.
5fill in blank
hard

Fill all three blanks to create a safe args bundle and navigate with arguments.

Android Kotlin
val action = NavGraphDirections.actionToDetailFragment([1] = userId)
navController.[2](action, [3])
Drag options to blanks, or click blank then click option'
AuserId
Bnavigate
Cnull
DbundleOf()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong argument name.
Using bundleOf() instead of null when no options are needed.