java – 如何在bundle中传递list <>
发布时间:2020-12-14 23:46:10 所属栏目:Java 来源:网络整理
导读:我有以下代码: ListValueActivity list = new ArrayListValueActivity(); list = setList(); Intent intent = new Intent(NOTIFICATION); Bundle bundle = new Bundle();bundle.put ????("list",list);intent.putExtra("bundle",bundle);sendBroadcast(inte
我有以下代码:
List<ValueActivity> list = new ArrayList<ValueActivity>(); list = setList(); Intent intent = new Intent(NOTIFICATION); Bundle bundle = new Bundle(); bundle.put ????("list",list); intent.putExtra("bundle",bundle); sendBroadcast(intent); 如何编写第5行以及如何在目标意图中使用getExtra 解决方法
您需要使用ValueActivity实现Parcelable接口,并且您需要实现CREATOR的writeToParcel()以及将Parcel作为参数的合适构造函数.请参阅Parcelable接口的文档.
要将列表放入Bundle,请使用: bundle.putParcelableArrayList("list",list); 要从目标活动中的Bundle中获取列表,请使用: List<ValueActivity> = listbundle.getParcelableArrayList("list"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |