0Pricing
Jetpack Compose Academy · Lesson

Passing Arguments Between Screens

Send data along the navigation route.

Passing Arguments Between Screens is a free Jetpack Compose Academy lesson on CoddyKit — lesson 3 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.

Screens Need Data

A detail screen needs to know which item to show. Navigation Compose lets you carry that data along the route itself.

Declare a Placeholder

Add a placeholder in curly braces to a route. It marks where a value will slot in when you navigate.

composable("profile/{userId}") { backStackEntry ->
    ProfileScreen()
}

Define the Argument

List each placeholder in arguments and give it a type. This tells Compose how to parse the value out of the route.

composable(
    "profile/{userId}",
    arguments = listOf(navArgument("userId") { type = NavType.IntType })
) { }

Send the Value

To pass data, build the route string with the real value in place of the placeholder. The receiving screen reads it back out.

navController.navigate("profile/42")

Read It from the Entry

The backStackEntry carries the arguments bundle. Pull your value out by the same name you declared in the route.

composable("profile/{userId}") { entry ->
    val id = entry.arguments?.getInt("userId")
    ProfileScreen(userId = id)
}

Choose the Right NavType

The NavType decides parsing: StringType, IntType, BoolType, and more. Match it to your data so values arrive correctly typed.

Optional Arguments

Use a query-style optional argument with a default value for data that may be missing, like a filter that is not always set.

composable(
    "search?query={query}",
    arguments = listOf(navArgument("query") { defaultValue = "" })
) { }

Pass Small Data Only

Route arguments are for identifiers, not whole objects. Send an id, then load the full data from your repository or ViewModel.

Encode Tricky Values

Strings with slashes or spaces can break a route. URL-encode them before navigating and decode after reading, just like a real URL.

Let the ViewModel Read It

A ViewModel can grab arguments from SavedStateHandle, so your screen stays clean and survives recreation with the right data.

class ProfileViewModel(state: SavedStateHandle) {
    val userId: Int = checkNotNull(state["userId"])
}

Keep Argument Names Aligned

The placeholder, the navArgument, and the lookup key must all use the same name. A mismatch returns null instead of your value.

Quick Check

How should you send a complex item to a detail screen?

Recap

You can now pass data by adding a placeholder to a route, typing it with navArgument, and reading it back from the back stack entry. 📦

Frequently asked questions

Is the “Passing Arguments Between Screens” lesson free?

Yes — the full text of “Passing Arguments Between Screens” 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 “Passing Arguments Between Screens”?

Send data along the navigation route. 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 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Passing Arguments 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 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

  1. NavController & NavHost
  2. Composable Destinations & Routes
  3. Passing Arguments Between Screens
  4. Back Stack & Deep Links
← Back to Jetpack Compose Academy