Kotlin StateFlow multiple subscriptions after returning from another Fragment

I’m trying to implement StateFlow in my app with MVVM architecture between ViewModel and Fragment. In ViewModel: … private val _eventDataState = MutableStateFlow<EventDataState>(EventDataState.Loading) val eventDataState: StateFlow<EventDataState> = _eventDataState … In Fragment: … override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) … lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.eventDataState.collect { eventDataState -> when (eventDataState) { is EventDataState.Loading… Read More Kotlin StateFlow multiple subscriptions after returning from another Fragment

flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) doesn't stop flows while App is in background

I’m trying to observe the result of the View Collection and upstream flows stopped. But viewModel.testFlow is still collecting while the App is in the background. Why can’t I observe the collection is stopped? Am I observing something wrong? ViewModel: val testFlow = flow<Int> { for (i in 1..100) { delay(1000) Timber.e("testFlow: EMIT = $i")… Read More flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) doesn't stop flows while App is in background