0
0
Android Kotlinmobile~5 mins

NavHost and NavController in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a NavHost in Android navigation?
A NavHost is a container that displays destinations (screens) managed by a NavController. It acts like a frame where different screens appear as you navigate.
Click to reveal answer
beginner
What role does the NavController play in Android navigation?
NavController controls app navigation within a NavHost. It lets you move between screens, handle back actions, and manage navigation state.
Click to reveal answer
intermediate
How do you connect a NavController to a NavHost in Kotlin?
You get the NavController from the NavHostFragment using: val navController = findNavController(R.id.nav_host_fragment). This links navigation actions to the NavHost.
Click to reveal answer
beginner
What is a navigation graph in Android navigation?
A navigation graph is an XML file that defines all possible destinations (screens) and actions (transitions) between them. It guides the NavController on where to go.
Click to reveal answer
intermediate
Why is using NavHost and NavController better than manual fragment transactions?
They simplify navigation by managing the back stack automatically, reducing code, and making navigation predictable and easier to maintain.
Click to reveal answer
What does a NavHost do in an Android app?
AManages network requests
BDisplays the current screen and hosts navigation destinations
CStores user data
DHandles background tasks
Which class controls navigation actions like moving between screens?
ANavHost
BViewModel
CFragmentManager
DNavController
How do you get a NavController instance in an Activity?
AfindNavController(R.id.nav_host_fragment)
Bnew NavController()
CgetSupportFragmentManager()
DfindViewById(R.id.nav_controller)
What file defines the navigation paths and destinations?
Anavigation graph XML
Bstrings.xml
Cstyles.xml
Dlayout.xml
Which benefit does NavController provide over manual fragment transactions?
ABetter UI animations
BFaster network calls
CAutomatic back stack management
DMore memory usage
Explain how NavHost and NavController work together to manage navigation in an Android app.
Think of NavHost as a stage and NavController as the director.
You got /4 concepts.
    Describe the steps to set up navigation using NavHost and NavController in a Kotlin Android app.
    Start from layout, then code, then navigation actions.
    You got /4 concepts.