如何传递列表<>捆绑 [英] how to passing list<> in bundle

查看:15
本文介绍了如何传递列表<>捆绑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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 行如何写以及在目标 Intent 中如何 getExtra

How to write line 5 and how getExtra in destination intent

推荐答案

你需要让 ValueActivity 实现 Parcelable 接口,你需要实现 writeToParcel() CREATOR 和一个合适的构造函数,它接受一个 Parcel 作为参数.参见Parcelable接口的文档.

You will need to have ValueActivity implement Parcelable interface and you will need to implement writeToParcel() the CREATOR and a suitable constructor that takes a Parcel as argument. See the documentation of Parcelable interface.

要将列表放入Bundle,请使用:

To put the list into the Bundle, use:

bundle.putParcelableArrayList("list", list);

要从目标活动的 Bundle 中获取列表,请使用:

To get the list out of the Bundle in the target activity, use:

List<ValueActivity> = listbundle.getParcelableArrayList("list");

这篇关于如何传递列表&lt;&gt;捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆