Passando Argumentos entre Telas
Envie dados pela rota de navegação.
Passando Argumentos entre Telas é uma aula grátis de Jetpack Compose Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Jetpack Compose Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Jetpack Compose Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. 📦
Aprenda Kotlin com um tutor de IA — grátis
Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.
- Cursos
- 30
- Aulas
- 120
Perguntas Frequentes
A aula “Passando Argumentos entre Telas” é grátis?
Sim — o texto completo de “Passando Argumentos entre Telas” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Jetpack Compose Academy, atualize para CoddyKit PRO. O curso de Jetpack Compose Academy inclui 4 aulas no total.
O que vou aprender em “Passando Argumentos entre Telas”?
Envie dados pela rota de navegação. Você pratica Jetpack Compose Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Jetpack Compose Academy?
Nenhuma experiência prévia é necessária. Jetpack Compose Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.
Quanto tempo leva a aula “Passando Argumentos entre Telas”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Jetpack Compose Academy?
Sim. Cada aula de Jetpack Compose Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- NavController e NavHost
- Destinos e Rotas Composable
- Passando Argumentos entre Telas
- Pilha de Retorno e Links Profundos