11

I have created a Jetpack compose navigation as follows:

val navController = rememberNavController()

Scaffold(
    bottomBar = { /* BottomBar code here */ }
){ innerPadding ->

    NavHost(
         navController = navController,
         startDestination = "navigation",
         modifier = Modifier.padding(innerPadding)
    ){

        composable("home") { Log.d(TAG, "Show home screen") }

        composable("account") { Log.d(TAG, "Show account screen") }

        composable("settings") { Log.d(TAG, "Show settings screen") }

    }

}

My problem is when ever I click on a nav item, the log message on the composable() function is printed twice per click in logcat. I may have missed something on the documentation. Why is this happening & how can I fix it?

Nic
  • 597
  • 1
  • 4
  • 17
  • I asked the [same question](https://stackoverflow.com/questions/69190119/jetpack-compose-recompose-with-success-state-twice-when-exiting-current-composab?noredirect=1&lq=1), couldn't find an answer, instead of doing one shot request in Composable root, i decided to use `LaunchedEffect`. – Thracian May 19 '22 at 07:29
  • see https://developer.android.com/jetpack/compose/mental-model#recomposition – uragiristereo May 20 '22 at 14:34

0 Answers0