There is a class Note

 public class Note implements Parcelable { private String author, title; private Date dateCreate, dateEdit; private ArrayList<String> bodyNote; public Note() { } public Note(String author, String title, Date dateCreate, Date dateEdit, ArrayList<String> bodyNote) { this.author = author; this.title = title; this.dateCreate = dateCreate; this.dateEdit = dateEdit; this.bodyNote = bodyNote; } public Note(Parcel parcel){ String[] data = new String[2]; parcel.readStringArray(data); author = data[0]; title = data[1]; } 

I created the primitive data for the Parcel constructor, a problem with data of type Date and ArrayList<String> . Tell me how to create them correctly?

    1 answer 1

    Should work

     public class Note implements Parcelable { private String author, title; private Date dateCreate, dateEdit; private ArrayList<String> bodyNote; public Note() { } protected Note(Parcel in) { author = in.readString(); title = in.readString(); dateCreate = new Date(in.readLong()); dateEdit = new Date(in.readLong()); bodyNote = in.createStringArrayList(); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(author); dest.writeString(title); dest.writeLong(dateCreate.getTime()); dest.writeLong(dateEdit.getTime()); dest.writeStringList(bodyNote); } public static final Creator<Note> CREATOR = new Creator<Note>() { @Override public Note createFromParcel(Parcel in) { return new Note(in); } @Override public Note[] newArray(int size) { return new Note[size]; } }; @Override public int describeContents() { return 0; } } 
    • one
      Thank. It is a pity that he did not think of Date to convert to long. - Alexander