机器人:如何把Parcelable对象的意图和使用捆绑的getParcelable方法是什么? [英] android : how put Parcelable object to intent and use getParcelable method of bundle?
问题描述
为什么要捆绑有getParcelableArrayList,getParcelable方法,但 目的只有方法putParcelableArrayListExtra? 我可以只发送对象< T>,而不是一个元素的ArrayList的? 对于什么呢getParcelable?
Why bundle has getParcelableArrayList, getParcelable methods, but intent has only method putParcelableArrayListExtra ? Can I transmit only object < T > , not ArrayList of one element ? For what then getParcelable ?
推荐答案
意图提供了一堆超载<一href="http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20android.os.Parcelable%29">putExtra()的方法。
Intent provides bunch of overloading putExtra() methods.
假设你有一个类Foo实现Parcelable得当,把它变成意图的活动:
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");
希望这有助于。
Hope this helps.
这篇关于机器人:如何把Parcelable对象的意图和使用捆绑的getParcelable方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!