Is there an easy way to convert a Map to a Bundle in android without explicit iteration?
Why?
Firebase returns a Map for Notification getData()
. I need to pass the data to an intent. Formerly GCM gave me a bundle, so I didn't need to worry about this.
here is how I did it in Kotlin
I guess a good old fashioned for loop is the easiest way:
Came across this same issue with firebase messaging and created a kotlin extension function for it. The gist is here, code below. Although I am using this method there are some caveats:
With this in mind, please use it as a guide not a definitive solution. I will keep the gist up to date as it evolves.
You can use
writeToParcel(Parcel out, int flags)
to generate aParcel
that could be similarly useful, since it's a parent class ofBundle
, and it's handily built into the Firebase framework as part of theRemoteMessage
class. Documentation is here.