0
0
Android Kotlinmobile~5 mins

Navigation component setup in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the Navigation Component in Android?
The Navigation Component is a part of Android Jetpack that helps you manage app navigation easily and consistently, handling fragment transactions and back stack automatically.
Click to reveal answer
beginner
Which XML file defines the navigation graph?
The navigation graph is defined in an XML file located in the res/navigation folder, usually named nav_graph.xml. It describes all destinations and actions.
Click to reveal answer
beginner
How do you add the Navigation Component dependencies in your Android project?
Add these dependencies in your app's build.gradle file: implementation "androidx.navigation:navigation-fragment-ktx:2.5.3" implementation "androidx.navigation:navigation-ui-ktx:2.5.3"
Click to reveal answer
beginner
What is the purpose of NavHostFragment?
NavHostFragment is a container that hosts navigation destinations (fragments). It swaps fragments as you navigate through the app.
Click to reveal answer
beginner
How do you trigger navigation to another fragment in Kotlin code?
Use the NavController to navigate, for example: findNavController().navigate(R.id.destinationFragment) This moves to the destination defined in the navigation graph.
Click to reveal answer
Where do you define the navigation graph XML file?
Ares/navigation folder
Bres/layout folder
Cres/values folder
Dres/drawable folder
Which class hosts the navigation destinations in your layout?
AViewPager
BFragmentManager
CActivity
DNavHostFragment
How do you navigate to another fragment in Kotlin using Navigation Component?
AfindNavController().navigate(R.id.destination)
BstartActivity(Intent(this, Destination::class.java))
CfragmentManager.beginTransaction()
DsetContentView(R.layout.destination)
Which dependencies are needed for Navigation Component in Kotlin?
Arecyclerview and cardview
Bappcompat and constraintlayout
Cnavigation-fragment-ktx and navigation-ui-ktx
Dmaterial and lifecycle-extensions
What does the Navigation Component automatically handle for you?
ADatabase queries
BFragment transactions and back stack
CNetwork requests
DUI animations
Explain how to set up the Navigation Component in an Android Kotlin project from scratch.
Think about the files and code needed to make navigation work.
You got /4 concepts.
    Describe the role of NavHostFragment and NavController in app navigation.
    One is a container, the other is a controller.
    You got /3 concepts.