Search code examples
javaandroidandroid-intentbroadcastreceiver

how to properly pack a List<Hashtable<String,List<String>>> in an Intent for broadcast?


On Android, I am trying to send a custom broadcast message using a custom Intent and BroadcastListeners. I have some custom data, in the format:

List<Hashtable<String,List<String>>> data;

When trying to use:

intent.putExtra("mydata", data);

I get the error:

The method putExtra(String, boolean) in the type Intent is not applicable for the  arguments (String, List<Hashtable<String,List<String>>>)

Looking at the Intent class, there are a bunch of public methods that overload putExtra(). However, none seem to meet the data that I am trying to send.

There seem to be a rather generic method

putExtra(String name, Bundle value)

However, I am not sure how to transform my data in to a Bundle to use this. Is this the right thing to do? Or is there a simpler method?


Solution

  • You want to have Serializable for putExtra(String name, Serializable s) version. However, List is an interface that does not extend Serializable. Try to declare it as ArrayList.