birdsofparadise
12/24/2020, 11:47 PMclass MyActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val navController = rememberNavController()
NavHost(navController, startDestination = "") {
composable("") { TestCompose() }
composable("test") { TestCompose() }
}
}
}
}
@Composable
fun TestCompose(vm: TestViewModel = viewModel()) {
}
Reading about the API viewModel it seems like using it in the manor I am, it's lifecycle gets attached to MyActivity
and thus if I navigate multiple TestCompose
views it will leak my ViewModelziv kesten
12/25/2020, 7:33 AMbirdsofparadise
12/25/2020, 4:54 PMziv kesten
12/25/2020, 5:08 PMbirdsofparadise
12/26/2020, 3:06 AMAdam Powell
12/26/2020, 4:02 AMIan Lake
12/29/2020, 11:19 PMcomposable
destination, not your activity, so that code is finebirdsofparadise
12/30/2020, 1:03 AM