0Pricing
Jetpack Compose Academy · Lekcja

Przekazywanie argumentów między ekranami

Przesyłaj dane wzdłuż trasy nawigacji

Przekazywanie argumentów między ekranami to bezpłatna lekcja Jetpack Compose Academy na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Jetpack Compose Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Jetpack Compose Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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. 📦

Często zadawane pytania

Czy lekcja „Przekazywanie argumentów między ekranami” jest bezpłatna?

Tak — pełny tekst „Przekazywanie argumentów między ekranami” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Jetpack Compose Academy, przejdź na CoddyKit PRO. Kurs Jetpack Compose Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Przekazywanie argumentów między ekranami”?

Przesyłaj dane wzdłuż trasy nawigacji Ćwiczysz Jetpack Compose Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Jetpack Compose Academy?

Nie wymagamy żadnego doświadczenia. Jetpack Compose Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.

Ile czasu zajmuje lekcja „Przekazywanie argumentów między ekranami”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Jetpack Compose Academy?

Tak. Każda lekcja Jetpack Compose Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. NavController i NavHost
  2. Miejsca docelowe i trasy Composable
  3. Przekazywanie argumentów między ekranami
  4. Stos wsteczny i deep linki
← Powrót do Jetpack Compose Academy