机器人:如何把Parcelable对象的意图和使用捆绑的getParcelable方法是什么?意图、机器人、对象、方法

2023-09-06 13:30:20 作者:神经病开心也笑难过也笑

为什么要捆绑有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 ?

推荐答案

意图提供了一堆超载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.

 
精彩推荐