在活动之间传递带有自定义 Parcelable Arraylist 的 HashMap
Pass HashMap with Custom Parcelable Arraylist between activities
我正在尝试在我的服务和 activity 之间传递 HashMap。我知道如何使用自定义对象传递 Arraylist。
但是没有找到从服务传递hashmap的解决方案。
我有服务,我想将 hashMap 发送到我的 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;
所以 bundle.putParcelableArrayList("si", allvalues),有什么方法可以传递 allvalues hashmap。我查看了 Bundle Class 但没有找到任何东西。
putParcelableArrayList() 接收 ArrayList<"Parcable Items">,而不是 HashMap。由于 HashMaps 和 ArrayLists 是可序列化的,putSerializable() 应该可以工作。
我正在尝试在我的服务和 activity 之间传递 HashMap。我知道如何使用自定义对象传递 Arraylist。 但是没有找到从服务传递hashmap的解决方案。
我有服务,我想将 hashMap 发送到我的 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;
所以 bundle.putParcelableArrayList("si", allvalues),有什么方法可以传递 allvalues hashmap。我查看了 Bundle Class 但没有找到任何东西。
putParcelableArrayList() 接收 ArrayList<"Parcable Items">,而不是 HashMap。由于 HashMaps 和 ArrayLists 是可序列化的,putSerializable() 应该可以工作。