问题描述
这是东西已经困扰我有一段时间了。
This is something that has bothered me for a while now.
如果我们有一些在我们的活动Parcelable对象,而且我们通过它使用捆绑进行分段,我一直认为,我们收到片段实际上是一个新的对象的对象。然而,今天在运行一些测试后,似乎在片段的对象是如在活动对象实际上相同。
If we have some kind of Parcelable object in our activity and we pass it to fragment using Bundle, I've always thought the object that we receive in fragment is actually a new object. However, after running some tests today, it seems the object in fragment is actually same as the object in activity.
这是否正确?
编辑:小澄。我指的不是对象的值。我指的是'=='比较。
Small clarification. I don't refer to object's values. I refer to the '==' comparison.
推荐答案
当你让你的对象 Parcelable
,然后你使用它传递到另一个活动意图
,是这样的:
When you make your object Parcelable
and then you pass it into another activity using Intent
,something like this:
Intent i = new Intent();
i.putExtra("name_of_extra", myParcelableObject);
您在另一个活动或片段接收对象是你之前传递给它确切的对象。
你可以接收对象是这样的:
the object you receive in another activity or fragment is the exact object you pass it before.you can receive the object in this way:
Intent i = getIntent();
MyParcelable myParcelableObject = (MyParcelable)i.getParcelableExtra("name_of_extra");
这篇关于是parcelable对象通过捆绑同原来的通过呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!