EDIT:: Updated code to show what concerns me: Changing properties of mData in Frag changes properties mData in Sender and their memory reference is the same..
I'm passing a custom data class into a child view via bundles, with the intent of returning data back to the parent. As such, it's convenient that my data object gets passed as a reference, and as such can be manipulated directly.
However, coming from iOS, this is of course against functional programming. I'm mostly just curious here, did I need to do more to implement Serializable? Or is it intended that putSerializable serializes the reference, not the value?
class Sender{
DataClass mData = new DataClass();
void openFragment(){
Bundle bundle = new Bundle();
bundle.putSerializable("Key", mData);
Frag frag = new Frag(); //@6945
//EDIT for test
{
testForEquality(bundle);
}
frag.setArguments(bundle);
pushFragment(frag);//Makes a new view appear on top
}
void testForEquality(Bundle bundle){
DataClass newData = (DataClass) bundle.getSerializable("Key");
Log.e("Equal", "" + (newData == mData); //TRUE
}
}
class Frag{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance){
DataClass mData = (DataClass) getArguments().getSerializable("Key"); //@6945
mData.stringA = "Different string value"; //Changes value here AND in Sender
}
}
class DataClass extends BaseDataClass implements Serializable{
//Some strings
//Some ArrayList<Integers>
//Some enums
//Some Errors
}