您可以使用Serializable
如下界面:
// pass:
intent.putExtra("MotherClass", obj);
// receive:
getIntent().getSerializableExtra("MotherClass");
甚至更好,Parcelable
如下使用(来自@BomberMan 的回答和这个博客):
public class CustomObject1 implements Parcelable {
// parcelable code CustomObject1
}
public class CustomObject2 implements Parcelable {
private CustomObject1 obj1;
// add CustomObject1 here with getter setter
// parcelable code for CustomObject2
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(obj1, flags);
}
private void readFromParcel(Parcel in) {
obj1 = in.readParcelable(CustomObject1.class.getClassLoader());
}
............
}