例えば、IntentからIntentになんらかのオブジェクトを受け渡したいときに、Parcelableを利用します。
ですが、このParcelableを受け取ったときに、思いがけない中身になっていたりします。
Googleさんの公式ドキュメントでは、
https://developer.android.com/reference/android/os/Parcelable.html
//書き込み
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mData);
}
//読み出し
private MyParcelable(Parcel in) {
mData = in.readInt();
}
となっていて、一つのデータしかありませんが、実際のところは複数のデータとかが存在していると思います。
その時、書き込んだ順番と、読みこむ順番を合わせておかないといけません。
//書き込み
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(hogehoge);
dest.writeString(mokemoke);
}
//読み込み
public User(Parcel in) {
hoghoge = in.readString();
mokemoke = in.readString();
}
