Android:如何将Parcelable对象传递给Intent并使用bundle的getParcelable方法? [英] Android: How to pass Parcelable object to intent and use getParcelable method of bundle?
本文介绍了Android:如何将Parcelable对象传递给Intent并使用bundle的getParcelable方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么捆绑包具有getParcelableArrayList
,getParcelable
方法;但
Intent
仅具有putParcelableArrayListExtra
方法?
我只能传送一个元素的object<T>
而不传送ArrayList
吗?
那么,getParcelable
是做什么的?
Why bundle has getParcelableArrayList
, getParcelable
methods; but
Intent
has only putParcelableArrayListExtra
method?
Can I transmit only object<T>
, not ArrayList
of one element?
Then, what is getParcelable
for?
推荐答案
Intent provides bunch of overloading putExtra() methods.
假设您有一个Foo类正确地实现了Parcelable,可将其放入Activity中的Intent中:
Suppose you have a class Foo implements Parcelable properly, to put it into Intent in an Activity:
Intent intent = new Intent(getBaseContext(), NextActivity.class);
Foo foo = new Foo();
intent.putExtra("foo ", foo);
startActivity(intent);
要从其他活动中获取它:
To get it from intent in another activity:
Foo foo = getIntent().getExtras().getParcelable("foo");
希望这会有所帮助.
这篇关于Android:如何将Parcelable对象传递给Intent并使用bundle的getParcelable方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文