Skip to content

Instantly share code, notes, and snippets.

@Vaibhav2002
Created November 9, 2022 14:06
Show Gist options
  • Save Vaibhav2002/5d92c53716bb97f24dd84d713005134d to your computer and use it in GitHub Desktop.
Save Vaibhav2002/5d92c53716bb97f24dd84d713005134d to your computer and use it in GitHub Desktop.
Collecting Flows using repeatOnLifecycle
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