Created
October 21, 2021 21:02
-
-
Save fergusonm/e1bad0723f62c5447832189bb54c3da1 to your computer and use it in GitHub Desktop.
Flow with lifecycle example
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
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