我的Parcelable类有问题吗?

时间:2013-04-21 19:45:39

标签: java android android-intent parcelable

我想知道我的班级是否有问题,因为我无法将额外的活动(由注释对象组成)从活动传递给另一个

以下是我的Parcelable类的代码:注意:

public class Note implements Parcelable {

    public static int compteur = 0;
    long id;
    String summary;
    String details;

    public Note(String summary, String details) {
        super();
        compteur = compteur + 1;
        this.id = compteur;
        this.summary = summary;
        this.details = details;
    }

    public Note() {
        super();
    }

    ///// getters and settters /////

    @Override
    public String toString() {
        return "Note " + id + " (" + summary + ") --> Details: " + details;
    }

    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int arg1) {
        // TODO Auto-generated method stub
        dest.writeLong(id);
        dest.writeString(summary);
        dest.writeString(details);

    }

    public static final Parcelable.Creator<Note> CREATOR = new Parcelable.Creator<Note>() {

        @Override
        public Note createFromParcel(Parcel in) {
            // TODO Auto-generated method stub
            return new Note(in);
        }

        public Note[] newArray(int size) {
            return new Note[size];
        }
    };

    private Note(Parcel in) {
        this.id = in.readInt();
        this.summary = in.readString();
        this.details = in.readString();
    }
}

或者问题可能在其他任何地方?

1 个答案:

答案 0 :(得分:0)

尝试制作接受Parcel公开的Note构造函数。

  public Note(Parcel in) {
        this.id = in.readInt();
        this.summary = in.readString();
        this.details = in.readString();
    }