Skip to content

Instantly share code, notes, and snippets.

@macsystems
Created December 1, 2019 16:52
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 macsystems/c212ad6aa429bc310789b7178fd2d29a to your computer and use it in GitHub Desktop.
Save macsystems/c212ad6aa429bc310789b7178fd2d29a to your computer and use it in GitHub Desktop.
write any type in an Intent
fun Intent.putAnyExtra(name: String, value: Any) {
when (value) {
is Int -> putExtra(name, value)
is Byte -> putExtra(name, value)
is Short -> putExtra(name, value)
is Long -> putExtra(name, value)
is Char -> putExtra(name, value)
is Float -> putExtra(name, value)
is Double -> putExtra(name, value)
is Boolean -> putExtra(name, value)
is IntArray -> putExtra(name, value)
is ByteArray -> putExtra(name, value)
is CharArray -> putExtra(name, value)
is ShortArray -> putExtra(name, value)
is LongArray -> putExtra(name, value)
is BooleanArray -> putExtra(name, value)
is CharSequence -> putExtra(name, value)
is String -> putExtra(name, value)
is Parcelable -> putExtra(name, value)
is Serializable -> putExtra(name, value)
is Bundle -> putExtra(name, value)
else -> error("Unhandled type ${value::class}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment