Sharing viewModel within Jetpack Compose Navigation

Consider passing your activity to viewModel() fun as viewModelStoreOwner parameter since ComponentActivity implements ViewModelStoreOwner interface: val viewModel: ConversionViewModel = viewModel(LocalContext.current as ComponentActivity) This code will return the same instance of ConversionViewModel in all your destinations.

How to navigate from a composable to an activity or a fragment in Jetpack Compose?

In newer version of compose use LocalContext. In older versions (1.0.0-alpha08 and before) use AmbientContext: @Composable fun MainScreen() { val context = LocalContext.current Button(onClick = { context.startActivity(Intent(context, ListActivity::class.java)) }) { Text(text = “Show List”) } }

Pass Parcelable argument with compose navigation

Warning: Ian Lake is an Android Developer Advocate and he says in this answer that pass complex data structures is an anti-pattern (referring the documentation). He works on this library, so he has authority on this. Use the approach below by your own. Edit: Updated to Compose Navigation 2.4.0-beta07 Seems like previous solution is not … Read more

Compose-Navigation: Remove previous composable from stack before navigating

In Jetpack Compose 1.0.0 to navigate and remove the previous Composable from the back stack You can use: navController.navigate(Screens.Login.name) { popUpTo(Screens.Splash.name) { inclusive = true } } The above code will navigate from the Splash screen to Login and will pop everything up, including the Splash screen. Navigate to a composable – docs

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)