Skip to content

Instantly share code, notes, and snippets.

@arjava
Created March 27, 2018 05:51
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 arjava/8b1dc87ae9069f179e2142cde0f74e3b to your computer and use it in GitHub Desktop.
Save arjava/8b1dc87ae9069f179e2142cde0f74e3b to your computer and use it in GitHub Desktop.
Handling back button in kotlin
override fun onOptionsItemSelected(item: MenuItem?) = when (item?.itemId) {
android.R.id.home -> consume { finish() }
else -> super.onOptionsItemSelected(item)
}
private inline fun consume(f: () -> Unit): Boolean {
f()
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment