Search code examples
javaandroidhashmapparcelableserializable

Android - passing hashmap through intent


I'm trying to pass a Hashmap of custom objects through an intent.

I am trying to use parcelable as that's what i read is the correct way to do things in android (i.e. parcelable over serializable).

However, when i try and get the hashmap using getParcelable, it can't find my hashmap in the intent, but getSerializable can.

Is it OK to use serializable for hashmaps? Is this my only option?


Solution

  • You can of course serialize your map, as long as your Objects are serializable. What you also could do is creating a separate singleton class (DataStore or so?) that saved your data. This way you don't need to pass the data from Activity to Activity. Or, even simpler, save the data in a public static variable.