如何传递列表<>捆绑 [英] how to passing list<> in bundle
本文介绍了如何传递列表<>捆绑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
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如何
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
,使用:
bundle.putParcelableArrayList("list", list);
从 Bundle中获取列表
在目标活动中,使用:
To get the list out of the Bundle
in the target activity, use:
List<ValueActivity> = listbundle.getParcelableArrayList("list");
这篇关于如何传递列表<>捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文