Created
November 9, 2022 14:06
-
-
Save Vaibhav2002/5d92c53716bb97f24dd84d713005134d to your computer and use it in GitHub Desktop.
Collecting Flows using repeatOnLifecycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viewLifecycleOwner.lifecycleScope.launch { | |
// This will start the collection when the state reaches STARTED and cancels when goes below | |
repeatOnLifecycle(Lifecycle.State.STARTED){ | |
flow.collect { | |
// Doing the work | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment