I have a complex object (which includes further objects and hashmaps). All objects implement Serializable
.
In the first activity I do:
public void secondActivity(MyObject o) {
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("myobject", o);
startActivity(intent);
finish();
}
Then, in the second activity I'm doing:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
MyObject o = (MyObject)intent.getSerializableExtra("myobject");
}
But when casting I'm getting this exception:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to myapp.MyObject
Is this the correct way to pass complex objects between activities? What am I missing?
Or should I implement singleton class?