Skip to content

Instantly share code, notes, and snippets.

@fergusonm
Last active March 15, 2021 19:18
Show Gist options
  • Save fergusonm/32b5be1af5bf6dd1f7f286c2f1081eda to your computer and use it in GitHub Desktop.
Save fergusonm/32b5be1af5bf6dd1f7f286c2f1081eda to your computer and use it in GitHub Desktop.
lanchWhenX flow collector
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// get your view model here
lifecycleScope.launchWhenStarted {
viewModel.eventsFlow
.collect {
when (it) {
MainViewModel.Event.NavigateToSettings -> {}
is MainViewModel.Event.ShowSnackBar -> {}
is MainViewModel.Event.ShowToast -> {}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment