As I know, repeatOnLifecycle is a suspend function. If the lifecycle state falls below the target, the coroutine launched for the block is cancelled.
Lastly, the repeatOnLifecycle function itself won’t resume the calling coroutine until the lifecycle is destroyed.
For example from https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda
```
// Create a new coroutine since repeatOnLifecycle is a suspend function
lifecycleScope.launch {
// The block passed to repeatOnLifecycle is executed when the lifecycle
// is at least STARTED and is cancelled when the lifecycle is STOPPED.
// It automatically restarts the block when the lifecycle is STARTED again.
repeatOnLifecycle(Lifecycle.State.STARTED) {
// Safely collect from locationFlow when the lifecycle is STARTED
// and stops collection when the lifecycle is STOPPED
locationProvider.locationFlow().collect {
// New location! Update the map
}
}
}
```
Since repeatOnLifecycle stops and restarts the flow collection when the lifecycle moves in and out of the target state, I think we needn't cancelling the upstream flow, because it will auto cancel when there is no active observer.