【问题标题】:Pass HashMap with Custom Parcelable Arraylist between activities在活动之间传递带有自定义 Parcelable Arraylist 的 HashMap
【发布时间】:2015-04-20 15:42:12
【问题描述】:

我试图在我的服务和活动之间传递 HashMap。我知道如何使用自定义对象传递 Arraylist。 但未能找到从服务传递 hashmap 的解决方案。

我有服务从我想将 hashMap 发送到我的活动的地方

   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,但没有找到任何东西。

【问题讨论】:

  • putSerializable() 怎么样?

标签: java android arraylist hashmap parcelable


【解决方案1】:

putParcelableArrayList() 接受 ArrayList,而不是 HashMap。由于 HashMaps 和 ArrayLists 是可序列化的,putSerializable() 应该可以工作。

【讨论】:

  • 但现在当我在做 HashMap> allvalues = new HashMap(); allvalues = resultData.getSerializable("si");它失败?类型不兼容
  • 您是否尝试将其转换为哈希图,如下所示: allvalues = (HashMap>) resultData.getSerializable("si");
猜你喜欢
  • 1970-01-01
  • 2015-10-14
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多