Reputation: 889
This is something that has bothered me for a while now.
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.
Is that correct?
EDIT: Small clarification. I don't refer to object's values. I refer to the '==' comparison.
Upvotes: 4
Views: 673
Reputation: 9477
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");
Upvotes: 4