Skip to content

Instantly share code, notes, and snippets.

@n8ebel
Created January 25, 2018 04:40
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 n8ebel/aa7cfbe7413b8b4657d9aea06115493c to your computer and use it in GitHub Desktop.
Save n8ebel/aa7cfbe7413b8b4657d9aea06115493c to your computer and use it in GitHub Desktop.
viewModel.lifecycleStatePub.subscribe { state ->
when (state) {
is Active -> {}
is FinishedOk, Cancelled -> finish()
is FinishedWithResult -> {
setResult(state.result, state.data)
finish()
}
is StartActivity -> {
val intent = Intent(this, state.target).apply {
putExtras(state.data)
}
startActivity(intent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment