我有以下代码:
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行怎么写以及destination intent中getExtra怎么写
最佳答案
您需要让 ValueActivity
实现 Parcelable
接口(interface),并且您需要实现 writeToParcel()
CREATOR
和一个以 Parcel
作为参数的合适的构造函数。参见Parcelable
接口(interface)的文档。
要将列表放入 Bundle
,请使用:
bundle.putParcelableArrayList("list", list);
要从目标 Activity 中的 Bundle
中获取列表,请使用:
List<ValueActivity> = listbundle.getParcelableArrayList("list");
关于java - 如何在 bundle 中传递 list<>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28190847/