Question regarding new androidx lifecycle (2.4.0) ...
# orbit-mvi
Question regarding new androidx lifecycle (2.4.0) and the article Isn’t the proper way to bound to the lifecycle is like?
Copy code
fun <STATE : Any, SIDE_EFFECT : Any> ContainerHost<STATE, SIDE_EFFECT>.collectAsState(
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): State<STATE> {
    val lifecycleOwner = LocalLifecycleOwner.current
    val lifecycleAwareStateFlow = remember(this, lifecycleOwner) {
        container.stateFlow.flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState)
    return lifecycleAwareStateFlow.collectAsState(currentState)
Mikolaj or Matt can correct me if I am wrong. My understanding is the
works only in case of cold
, where the repeat on lifecycle can cancel the `Flow`'s event generator. --- Blogpost example -- Looking at the example in the post they accept a cold flow stream that provides Location data.
Copy code
fun LocationScreen(locationFlow: Flow<Flow>) 
Unsubscribing from
while compose is in the background might reduce the pressure on location services and we can resubscribe when the app comes to the foreground. --- ContainerHost --- ContainerHost contains a
which is hot and accepts state regardless the number of subscribers connected to the `StateFlow`'s instance. Adding a repeat won't cancel the generating source as it is providing states to the
@kioba basically you’re right as the main point of the new API is to cancel the underlying producer properly, but also, one more thing is about effects -> as the collect coroutine is now just suspended and not canceled, there is a chance to miss effects into the void during the resume (e.g. view destroy)
sorry, I haven't looked at the SideEffects before, It might be the case but I am not exactly sure how you mean missing an effect as the collector suspended.