Is it required to use the repeatOnLifeycle with st...
# flow
v
Is it required to use the repeatOnLifeycle with state flow collecting in the UI ? As I am updating the UI only when it is visible on the screen.
e
If your requirement is to collect state emission efficiently based on UI lifecycle, then yes repeatOnLifecycle is the recommended approach one.
👍 1
e
it's not required:
lifecycleScope.launchWhenStarted
will pause when not visible. but
repeatOnLifecycle
is the better choice in most cases, as it will cancel and restart coroutines instead of just suspending them
👍 1