8

Why does navigation composable call twice? If I set a breakpoint on the Text I will get two stops when the app runs. Thank you for your answers.

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val navController = rememberNavController()
            var i: Int = 0
            NavHost(navController = navController, startDestination = "s1") {
                composable("s1") {
                    i++
                    Text("$i")

                }
            }
        }
    }
}
Сергей
  • 176
  • 1
  • 12
  • Seems related to this issue - https://stackoverflow.com/a/22224038/2191796 . Even after moving `super` call after setContent I still get the double onCreate call. The other suggestion in that thread was creating a new thread/runnable while still inside onCreate. So it seems something about Compose Navigation is creating a new thread or runnable. – ryanholden8 Sep 06 '22 at 14:24

0 Answers0