Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a map into a parcel?

Tags:

java

android

In my android application I have an activity containing a Parcelable object (implements Parcelable).

That object contains a map.

When I try to do the following in the writeToParcel() method:

parcel.writeMap(myMap);

I get the following comment from the API:

Please use writeBundle(Bundle) instead. Flattens a Map into the parcel at the current dataPosition(), growing dataCapacity() if needed. The Map keys must be String objects. The Map values are written using writeValue(Object) and must follow the specification there.

How am I supposed to do it? How am I supposed to use the writeBundle(myMap) here?

like image 879
Chaiavi Avatar asked Feb 17 '12 11:02

Chaiavi


1 Answers

Bundle is just a map. Iterate through your map, put each mapping into a newly created Bundle object and call writeBundle over it. May not be the best solution, but, a workable solution.

like image 123
SurenNihalani Avatar answered Oct 17 '22 23:10

SurenNihalani