Skip to content

Instantly share code, notes, and snippets.

@ralphgabrielle
Last active October 31, 2019 05:43
Show Gist options
  • Save ralphgabrielle/3a5a19f9c83693a708bd6ab4e00f7732 to your computer and use it in GitHub Desktop.
Save ralphgabrielle/3a5a19f9c83693a708bd6ab4e00f7732 to your computer and use it in GitHub Desktop.
Intent Extension (Kotlin)
fun fillIntentWithParams(
intent: Intent,
params: Array<out Pair<String, Any?>>
) {
params.forEach {
when (val value = it.second) {
is String -> intent.putExtra(it.first, value)
is Int -> intent.putExtra(it.first, value)
is Double -> intent.putExtra(it.first, value)
else -> throw Exception("Invalid intent parameter type for : ${it.first}")
}
}
}
/*
Use it with :
fillIntentWithParams(intent,
"first" to 1, "second" to 2, "third" to "3"
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment