我有以下代码:
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
解决方法
@H_301_9@ 您需要使用ValueActivity实现Parcelable接口,并且您需要实现CREATOR的writeToParcel()以及将Parcel作为参数的合适构造函数.请参阅Parcelable接口的文档.要将列表放入Bundle,请使用:
bundle.putParcelableArrayList("list",list);
要从目标活动中的Bundle中获取列表,请使用:
List<ValueActivity> = listbundle.getParcelableArrayList("list");