https://kotlinlang.org logo
#flow
Title
# flow
v

Vikas Singh

06/09/2022, 7:10 PM
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

Erick Sumargo

06/09/2022, 11:35 PM
If your requirement is to collect state emission efficiently based on UI lifecycle, then yes repeatOnLifecycle is the recommended approach one.
👍 1
e

ephemient

06/09/2022, 11:38 PM
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
8 Views