Skip to content

Instantly share code, notes, and snippets.

@fergusonm
Created October 21, 2021 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fergusonm/e1bad0723f62c5447832189bb54c3da1 to your computer and use it in GitHub Desktop.
Save fergusonm/e1bad0723f62c5447832189bb54c3da1 to your computer and use it in GitHub Desktop.
Flow with lifecycle example
viewModel.events
.onEach {
// can get cancelled when the lifecycle state falls below min
}
.flowWithLifecycle(lifecycle = viewLifecycleOwner.lifecycle, minActiveState = Lifecycle.State.STARTED)
.onEach {
// Do things
}
.launchIn(viewLifecycleOwner.lifecycleScope)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment