0
0
Android Kotlinmobile~10 mins

Why navigation manages app flow in Android Kotlin - Test Your Understanding

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

Complete the code to navigate from one screen to another using Navigation Component.

Android Kotlin
findNavController().navigate([1])
Drag options to blanks, or click blank then click option'
AR.id.action_home_to_detail
BstartActivity(Intent(this, DetailActivity::class.java))
CsetContentView(R.layout.detail)
Dfinish()
Attempts:
3 left
💡 Hint
Common Mistakes
Using startActivity instead of Navigation Component navigation.
Passing layout resource instead of action ID.
Calling finish() which closes the current screen.
2fill in blank
medium

Complete the code to define a navigation action in the navigation graph XML.

Android Kotlin
<action android:id="@+id/[1]" app:destination="@id/detailFragment" />
Drag options to blanks, or click blank then click option'
Ago_detail
Bopen_detail
Cnavigate_to_detail
Daction_home_to_detail
Attempts:
3 left
💡 Hint
Common Mistakes
Using arbitrary names that don't match code references.
Missing the 'action_' prefix.
3fill in blank
hard

Fix the error in the code to correctly navigate with arguments.

Android Kotlin
val action = HomeFragmentDirections.[1](userId)
findNavController().navigate(action)
Drag options to blanks, or click blank then click option'
AactionHomeToDetail
BnavigateToDetail
CgoToDetail
DopenDetail
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names that don't exist in directions class.
Not passing required arguments.
4fill in blank
hard

Fill both blanks to check if the current destination is the home screen before navigating.

Android Kotlin
if (findNavController().currentDestination?.id == [1]) {
  findNavController().navigate([2])
}
Drag options to blanks, or click blank then click option'
AR.id.homeFragment
BR.id.action_home_to_detail
CR.id.detailFragment
DR.id.action_detail_to_home
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with action IDs instead of fragment IDs.
Using wrong action IDs for navigation.
5fill in blank
hard

Fill all three blanks to create a navigation graph XML snippet with a start destination and two fragments.

Android Kotlin
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  app:startDestination="@id/[1]">
  <fragment android:id="@+id/[2]" android:name="com.example.HomeFragment" />
  <fragment android:id="@+id/[3]" android:name="com.example.DetailFragment" />
</navigation>
Drag options to blanks, or click blank then click option'
AhomeFragment
CdetailFragment
DmainFragment
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same ID for both fragments.
Setting startDestination to a non-existent fragment.