Created
December 1, 2019 16:52
-
-
Save macsystems/c212ad6aa429bc310789b7178fd2d29a to your computer and use it in GitHub Desktop.
write any type in an Intent
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
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