I define a sharedFlow in MainViewModel like
class MainViewModel : ViewModel{
val _sharedFlow: MutableSharedFlow()
val sharedFlow = _sharedFlow.asSharedFlow()
}
Then I have a activity
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED){
viewModel.sharedFlow.collect{
Log.i("View","Here can be call.")
}
Log.i("View","this line will never call.")
}
}
when I click a button to emit , collect will be called , then when I rotate this or back to previous activity , when this activity destroy it should be leave"collect" block then execute
Log.i("View","this line will never call")
right? but it doesn't ,does anyone knows why ? thanks