Argumente zwischen Bildschirmen übergeben
Übergeben Sie Daten entlang der Navigationsroute.
Argumente zwischen Bildschirmen übergeben ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Jetpack Compose Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 📦
Häufig gestellte Fragen
Ist die Lektion „Argumente zwischen Bildschirmen übergeben“ kostenlos?
Ja — der vollständige Text von „Argumente zwischen Bildschirmen übergeben“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Jetpack Compose Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Argumente zwischen Bildschirmen übergeben“?
Übergeben Sie Daten entlang der Navigationsroute. Du übst Jetpack Compose Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Jetpack Compose Academy zu starten?
Keine Vorkenntnisse erforderlich. Jetpack Compose Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.
Wie lange dauert die Lektion „Argumente zwischen Bildschirmen übergeben“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Jetpack Compose Academy-Lektion Code schreiben und ausführen?
Ja. Jede Jetpack Compose Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- NavController und NavHost
- Composable-Ziele und Routen
- Argumente zwischen Bildschirmen übergeben
- Back Stack und Deep Links