Reputation: 211
I have a Custom Type object that implements Serializable and i'm able to sucessfully pass this object through my Activities.
Now the situation is this:
On the Activity 1 the CustomObject instance has a String property with the value "A" set and is passed to the Activity 2 as an Extra:
Intent intent = new Intent(getApplicationContext(), Activity_2.class);
intent.putExtra("CUSTOM_OBJECT", customObjectInstance);
startActivityForResult(intent, 0);
On the Activity 2, i retrieve the CustomObject from the Intent and modify the property value from "A" to "B".
When i press the back button, going from Activity 2 back to Activity 1, the value on the CustomObject's property is "A" again!
I checked the object's hash code and have confirmed that is the same instance on both Activities, and still can't figure it out why this is happening.
EDIT:
As requested, about the code where i set the property value, it is as simple as it can be:
On Activity 2:
CustomObject obj = (CustomObject) getIntent().getExtras().getSerializable("CUSTOM_OBJECT");
obj.setProperty("B");
Upvotes: 3
Views: 1839
Reputation: 400
Intent's extras contain values only. You could handle parameters by reference by extending the Application class and deploying "global" variables.
Althought you express that both object's hash code is the same, i am pretty certain each Activity handles its own set of local variables. In your tests, objects in Activities A and B are independent of each other.
Hope it helps.
Upvotes: 2
Reputation: 615
Are you calling setResult(int) in the Activity returning a result? Here's the docs on starting Activities for results.
It must always supply a result code, which can be the standard results RESULT_CANCELED, RESULT_OK, or any custom values starting at RESULT_FIRST_USER. In addition, it can optionally return back an Intent containing any additional data it wants. All of this information appears back on the parent's Activity.onActivityResult(), along with the integer identifier it originally supplied.
If a child activity fails for any reason (such as crashing), the parent activity will receive a result with the code RESULT_CANCELED.
http://developer.android.com/reference/android/app/Activity.html#StartingActivities
Upvotes: 0