i am trying to pass the gson serialised object to intent by using the below code
intent.putExtra(\"com.example\", vo); // vo is the gson
I added implements Serializable
to my model AND other models (sub-models) used by my model. Then I can pass the GSON object via Intent:
public class MyModel implements Serializable {
SubModel subModel;
}
public class SubModel implements Serializable {
...
}
In fragment:
Intent startIntent = new Intent(getContext(), NextActivity.class);
startIntent.putExtra("mymodel", myModelObject);
startActivity(startIntent);
In next activity:
Intent intent = getIntent();
MyModel mymodel = (MyModel) intent.getSerializableExtra("mymodel");
// test if we get the model correctly:
setTitle(mymodel.getName());