gpt4 book ai didi

java - 如何在 bundle 中传递 list<>

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:08:11 24 4
gpt4 key购买 nike

我有以下代码:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com