Alex
08/14/2024, 7:08 AMLifecycle.STARTED
for flow collection, so that collection ends when the app is sent to the background, but the following code cancels and resumes at the same time in my testing (rotation, sending app into the background via home button, switching apps etc)
Can someone tell me when there will be a tangible difference between using the Lifecycle.STARTED
and just using LaunchedEffect
?
Code:
LaunchedEffect(Unit) {
try {
Log.v("LaunchedEffect", "LaunchedEffect scope started")
delay(10_000_000)
} catch (cancellation: CancellationException) {
Log.v("LaunchedEffect", "LaunchedEffect scope ended")
}
}
val lifecycle = LocalLifecycleOwner.current
LaunchedEffect(Unit) {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
try {
Log.v("LaunchedEffect", "Lifecycle scope started")
delay(10_000_000)
} catch (cancellation: CancellationException) {
Log.v("LaunchedEffect", "Lifecycle scope ended")
}
}
}
Alex
08/14/2024, 7:13 AM