能不能通过一个ArrayList< Parcelable>到活动 [英] Can't pass an ArrayList<Parcelable> to an activity

查看:113
本文介绍了能不能通过一个ArrayList< Parcelable>到活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在code

ArrayList<MyObject> list = new ArrayList<MyObject>();
list.add(new MyObject());
Intent intent = new Intent(this, ReceiverActivity.class);
intent.putExtra("list", list);
startActivity(intent);

ReceiverActivity

ReceiverActivity

List<MyObject> list = (List<MyObject>)getIntent().getExtras().getParcelable("list");

下面列表为空。另外这个不工作:

Here list is null. Also this doesn't work:

List<MyObject> list = (List<MyObject>)getIntent().getExtras().getSerializable("list");

MyObject的是Parcelable,我实现了所有需要的方法。我想这个实现是没有问题的,因为否则我会recive其他类型的异常。但我不明白,除了列表中任何事情都是空。

MyObject is Parcelable, I implemented all required methods. I guess this implementation is not the problem, because otherwise I would recive other kind of exceptions. But I don't get anything besides list is null.

在此先感谢...

现在我发现这一点:

List<Parcelable> list = (List<Parcelable>)getIntent().getParcelableArrayListExtra("list");

这是在接收活动中使用,但我怎么把它和我如何获得名单,其中,为MyObject&GT; 名单,其中, Parcelable&GT;

that has to be used in the receiver activity, but how do I send it and how do I get List<MyObject> from List<Parcelable> ?

推荐答案

使用 i.putParcelableArrayListExtra(名称,值)其中i是你的意图。不使用putExtra()的parcelable的ArrayList

USe i.putParcelableArrayListExtra(name, value) where i is your intent. Dont use putExtra() for a parcelable ArrayList.

这篇关于能不能通过一个ArrayList&LT; Parcelable&GT;到活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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