Skip to content

Instantly share code, notes, and snippets.

@oscargrgm
Last active February 25, 2021 11:24
Show Gist options
  • Save oscargrgm/02d2f6c81ea25308640616d1a2de49c6 to your computer and use it in GitHub Desktop.
Save oscargrgm/02d2f6c81ea25308640616d1a2de49c6 to your computer and use it in GitHub Desktop.
Useful Activity's extension functions.
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