Last active
February 25, 2021 11:24
-
-
Save oscargrgm/02d2f6c81ea25308640616d1a2de49c6 to your computer and use it in GitHub Desktop.
Useful Activity's extension functions.
This file contains hidden or 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
inline fun <reified T : Activity> Activity.launchActivity(extras: Bundle? = null) { | |
val intent = Intent(this, T::class.java).apply { | |
extras?.let { putExtras(it) } | |
} | |
startActivity(intent) | |
} | |
inline fun <reified T : Any> Activity.extra(key: String, default: T) = lazy { | |
val value = intent?.extras?.get(key) | |
if (value is T) value else default | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment