包含另一个 Parcelable 对象的 Parcelable 对象

包含 parcelable 类的类的示例:

public class Repository implements Parcelable {
    private String name;
    private Owner owner;
    private boolean isPrivate;
 
    public Repository(String name, Owner owner, boolean isPrivate) {
        this.name = name;      
        this.owner = owner;
        this.isPrivate = isPrivate;
    }
 
    protected Repository(Parcel in) {      
        name = in.readString();
        owner = in.readParcelable(Owner.class.getClassLoader());
        isPrivate = in.readByte() != 0;
    }
 
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeParcelable(owner, flags);
        dest.writeByte((byte) (isPrivate ? 1 : 0));
    }
 
    @Override
    public int describeContents() {
        return 0;
    }
 
    public static final Creator<Repository> CREATOR = new Creator<Repository>() {
        @Override
        public Repository createFromParcel(Parcel in) {
            return new Repository(in);
        }
 
        @Override
        public Repository[] newArray(int size) {
            return new Repository[size];
        }
    };
 
    //getters and setters
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public Owner getOwner() {
        return owner;
    }
 
    public void setOwner(Owner owner) {
        this.owner = owner;
    }
   
     public boolean isPrivate() {
        return isPrivate;
    }
 
    public void setPrivate(boolean isPrivate) {
        this.isPrivate = isPrivate;
    }
}

所有者只是一个普通的可分类类。