NavController & NavHost
Define your app's navigation graph.
NavController & NavHost is a free Jetpack Compose Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Moving Between Screens
Real apps have many screens. Navigation Compose is the official library that lets you move between them without juggling fragments or activities. 🧭
Add the Dependency
Navigation lives in its own artifact. Add androidx.navigation:navigation-compose to your module's build file before you can use any of it.
dependencies {
implementation("androidx.navigation:navigation-compose:2.7.7")
}Meet the NavController
The NavController is the brain of navigation. It tracks where you are, remembers history, and carries out every move you ask for.
Remember the Controller
You create one with rememberNavController() so it survives recomposition. Make it once near the top of your app and pass it down.
val navController = rememberNavController()Meet the NavHost
The NavHost is the container that swaps screens in and out. It shows exactly one destination at a time, based on the controller.
Wire Host to Controller
A NavHost needs two things: the navController that drives it and a startDestination that says which screen to show first.
NavHost(
navController = navController,
startDestination = "home"
) { }The startDestination
The startDestination is the route shown when the app opens. It is also the screen users land on after the back stack empties.
Declaring Destinations
Inside the NavHost lambda you list your screens with composable("route"). Each one ties a route name to the UI it should show.
NavHost(navController, startDestination = "home") {
composable("home") { HomeScreen() }
composable("profile") { ProfileScreen() }
}Navigate by Route
To change screens, call navController.navigate("route"). The host sees the request and swaps in the matching destination instantly.
Button(onClick = { navController.navigate("profile") }) {
Text("Open profile")
}One Controller, One Host
Keep a single NavController paired with a single NavHost for an app's main flow. Sharing one source of truth avoids confusing, out-of-sync history.
Why Routes Are Strings
Routes are just String identifiers, like tiny URLs inside your app. This keeps destinations decoupled and easy to link later.
Quick Check
Which piece actually performs the screen change?
Recap
You met the duo behind navigation: the NavController drives moves and history, while the NavHost shows one destination at a time from your route list. 🎉
Frequently asked questions
Is the “NavController & NavHost” lesson free?
Yes — the full text of “NavController & NavHost” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.
What will I learn in “NavController & NavHost”?
Define your app's navigation graph. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Jetpack Compose Academy?
No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “NavController & NavHost” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Jetpack Compose Academy lesson?
Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- NavController & NavHost
- Composable Destinations & Routes
- Passing Arguments Between Screens
- Back Stack & Deep Links