Colton Idle
08/23/2022, 8:12 AMval lifecycle = LocalLifecycleOwner.current.lifecycle
DisposableEffect(lifecycle) {
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_RESUME) {
vm.doThing()
}
}
lifecycle.addObserver(observer)
onDispose { lifecycle.removeObserver(observer) }
}
Colton Idle
08/23/2022, 8:14 AMvm.someFlow.collectAsStateWithLifecycle()
and I'm curious if I could somehow reuse this collectAsStateWithLifecycle function that's provided to us.Tolriq
08/23/2022, 8:48 AM@Composable
fun StartOnResume(block : suspend () -> Unit) {
... your helper
}
Then where wanted just StartOnResume { vm.doThing() }Colton Idle
08/23/2022, 8:58 AMFrancesc
08/23/2022, 4:04 PMLiveData
as state, similar to what you can do with `flow`s, would that work for you?Francesc
08/23/2022, 4:04 PMIan Lake
08/23/2022, 5:48 PM