8

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?

Damian Kozlak
  • 6,719
  • 10
  • 42
  • 50
Chaiavi
  • 689
  • 8
  • 22
  • You can get some help from [here](http://stackoverflow.com/questions/8254654/how-convert-write-java-util-map-into-parcel-in-a-smart-way).. – Haresh Chaudhary Feb 17 '12 at 12:07
  • http://android-orchestration.googlecode.com/svn-history/r162/trunk/Orchestration/src/orchestration/android/parcelable/ParcelableAndroidTaskDTO.java – Lalit Poptani Feb 17 '12 at 12:36
  • Thank you both, so there is no simple writeMap way. It seems that I need to insert the actual map entries one by one. – Chaiavi Feb 17 '12 at 13:04

1 Answers1

5

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.

SurenNihalani
  • 1,210
  • 2
  • 14
  • 28