Skip to content

Instantly share code, notes, and snippets.

@fergusonm
Created January 26, 2021 23:07
Show Gist options
  • Save fergusonm/35a9b2ac4ba885ffc659db492f1f83c2 to your computer and use it in GitHub Desktop.
Save fergusonm/35a9b2ac4ba885ffc659db492f1f83c2 to your computer and use it in GitHub Desktop.
flow observation between start and stop
override fun onStart() {
super.onStart()
job = viewModel.eventsFlow
.onEach {
when (it) {
MainViewModel.Event.NavigateToSettings -> {}
is MainViewModel.Event.ShowSnackBar -> {}
is MainViewModel.Event.ShowToast -> {}
}
}
.launchIn(viewLifecycleOwner.lifecycleScope)
}
override fun onStop() {
super.onStop()
job?.cancel()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment