Created
March 27, 2018 05:51
-
-
Save arjava/8b1dc87ae9069f179e2142cde0f74e3b to your computer and use it in GitHub Desktop.
Handling back button in kotlin
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
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