Christopher Mederos
08/05/2025, 5:29 AMcollectAsStateWithLifecycle
stops getting new values after restoring a view model after navigation.
However, collecting without lifecycle does keep updating
@Composable
fun MyScreen(viewModel: MyViewModel = koinViewModel()) {
val scope = rememberCoroutineScope()
// collectLatest: Does Update
scope.launch {
viewModel.uiState.collectLatest { state -> println("collectLatest Id: ${state.id}") }
}
// collectAsState: Does Update
val uiState by viewModel.uiState.collectAsState()
Text("collectAsState Id: ${uiState.id}: ")
// collectAsStateWithLifecycle: Does NOT Update
val uiStateWithLifecycle by viewModel.uiState.collectAsStateWithLifecycle()
Text("collectAsStateWithLifecycle Id: ${uiStateWithLifecycle.id}: ")
}
Any ideas on where I should go looking for a fix?Christopher Mederos
08/05/2025, 6:22 AM