0

I am trying to pass the HashMap between between my services and activity. I know how to pass Arraylist with custom objects. But failed to find the solutions for passing hashmap from service.

I have service from where I want to send hashMap to my activity

   public void getpProperies(ArrayList<property> values){
    if(values != null && values.size() > 0){
        for(property si : values){
            if(si instanceof esOtherProperty){
                Log.d(TAG, "Data "+ ((esOtherProperty) si).name);

            }
            if(si instanceof esEmpProperty){
                Log.d(TAG, "EMP Data "+ ((esEmpProperty) sig).name);
            }
        }
    }

    Bundle bundle = new Bundle();
    bundle.putParcelableArrayList("si", allvalues);
    if(resultReceiver != null)
    resultReceiver.send(100,bundle);
}
private HashMap<String, ArrayList<esProperty>> allvalues;

so instead bundle.putParcelableArrayList("si", allvalues), is there any way to pass allvalues hashmap. I looked in Bundle Class but did not find anything.

user3290805
  • 445
  • 2
  • 10
  • 28

1 Answers1

2

putParcelableArrayList() takes in an ArrayList<"Parcable Items">, not a HashMap. Since HashMaps and ArrayLists are Serializable, putSerializable() should work.

CodyF
  • 4,977
  • 3
  • 26
  • 38
  • but now when I am doing HashMap> allvalues = new HashMap<>(); allvalues = resultData.getSerializable("si"); it fails? with incompatible types – user3290805 Apr 20 '15 at 15:55
  • Did you try casting it to a hashmap, something like this: allvalues = (HashMap>) resultData.getSerializable("si"); – CodyF Apr 20 '15 at 16:26