Search code examples
androidfirebasebundlefirebase-cloud-messaging

Convert Map to Bundle in android


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.


Solution

  • I guess a good old fashioned for loop is the easiest way:

        Bundle bundle = new Bundle();
        for (Map.Entry<String, String> entry : getData().entrySet()) {
            bundle.putString(entry.getKey(), entry.getValue());
        }