Error While Passing An Object From An Activity To Another (Using Parcelable)

半城伤御伤魂 提交于 2019-12-01 18:06:26

You need to implement the code to write and read your class fields from parcel.

In writeToParcel:

@Override
public void writeToParcel(Parcel dest, int flags) {
      dest.writeString(st_AcadimicNumber);
      dest.writeString(st_Name);
      dest.writeString(st_Class);
}

The Parcel CREATOR:

public static final Parcelable.Creator<Track> CREATOR
= new Parcelable.Creator<Track>() {
    public Student createFromParcel(Parcel in) {
        return new Track(in);
    }

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

And the constructor:

public Student (Parcel source){
      /*
       * Reconstruct from the Parcel. Keep same order as in writeToParcel()
       */
      st_AcadimicNumber = source.readString();
      st_Name = source.readString();
      st_Class = source.readString();
}   

And it's done.

Regards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!