0Pricing
Android Academy · Lesson

Navigating Between Screens

Move forward and back between destinations.

Navigating Between Screens is a free Android Academy lesson on CoddyKit — lesson 2 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 Android Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Moving Forward

Once your NavHost is set up, you move to another screen by calling navigate on the NavController with the target route.

navController.navigate("details")

Triggering from a Button

Navigation usually happens in a callback, such as a button's onClick.

Button(onClick = { navController.navigate("details") }) {
    Text("Open details")
}

The Back Stack

Each navigate pushes the new destination onto the back stack. The system back button automatically pops it, returning to the previous screen.

popBackStack

To go back programmatically (for example from a custom "Up" button), call popBackStack. It removes the current destination and returns to the previous one.

navController.popBackStack()

navigateUp

navigateUp() is similar and is the right choice for the toolbar Up arrow. It respects the navigation hierarchy.

navController.navigateUp()

Avoiding Duplicate Destinations

Tapping a button twice quickly could push the same screen twice. Use launchSingleTop = true to avoid stacking duplicate copies of a destination.

navController.navigate("details") {
    launchSingleTop = true
}

popUpTo

popUpTo clears part of the back stack while navigating. Useful after login: jump to home and remove the login screen so back does not return to it.

navController.navigate("home") {
    popUpTo("login") { inclusive = true }
}

inclusive

inclusive = true means the target of popUpTo is also removed. With inclusive = false, popping stops just above it.

Keep Screens Decoupled

Instead of passing the whole NavController into every screen, pass lambdas. The screen calls onOpenDetails() and does not know about navigation internals.

@Composable
fun HomeScreen(onOpenDetails: () -> Unit) {
    Button(onClick = onOpenDetails) { Text("Details") }
}

Wiring the Lambda

The NavHost connects the lambda to a real navigate call, keeping navigation logic in one place.

composable("home") {
    HomeScreen(onOpenDetails = {
        navController.navigate("details")
    })
}

Putting It Together

Home navigates to details; details goes back with the Up arrow.

composable("home") {
    HomeScreen(onOpenDetails = { navController.navigate("details") })
}
composable("details") {
    DetailsScreen(onBack = { navController.popBackStack() })
}

Quick Check

Which call returns the user to the previous screen programmatically?

Recap

Navigating:

  • navigate("route") pushes a destination.
  • popBackStack() / navigateUp() go back.
  • Use launchSingleTop and popUpTo { inclusive } to control the stack.
  • Pass lambdas, not the controller, to keep screens reusable.

Frequently asked questions

Is the “Navigating Between Screens” lesson free?

Yes — the full text of “Navigating Between Screens” is free to read here on the web, and the Android 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 Android Academy course, upgrade to CoddyKit PRO.

What will I learn in “Navigating Between Screens”?

Move forward and back between destinations. You practise Android 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 Android Academy?

No prior experience is required. Android Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Navigating Between Screens” 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 Android Academy lesson?

Yes. Every Android 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

  1. Setting Up NavHost
  2. Navigating Between Screens
  3. Passing Arguments
  4. Bottom Navigation
← Back to Android Academy