Open greatpuzzlex opened 3 years ago
You should only call navigate() as part of a callback and not as part of your composable itself, to avoid calling navigate() on every recomposition.
From: https://developer.android.com/jetpack/compose/navigation
To be specific, your Greeting
composable will create a navigation request every single time it's rendered.
To work around, put navigation.navigate("greeting2")
into a button callback. Currently the way it's written Greeting
may get a chance to display because there is no delay before navigating to "greeting2"
.
The other way, if you want to navigate based on a data change:
if (dataNeededBeforeNavigating != null) {
LaunchedEffect(Unit) {
navigation.navigate("greeting2")
}
}
邮件已经收到了,谢谢!
Navigation to another routes creates infinite loop of recomposition in navhost. Here is my code:
jetpack navigation-compose : androidx.navigation:navigation-compose:2.4.0-alpha06