あるアクティビティから別のアクティビティにクラスの配列リストを渡したいのですが、同じことを行うために、クラスはParcelableを実装しています。問題は、クラス内のいくつかのフィールドがnullであるということです。nullでない値のみをチェックして送信する方法。これは、writeToParcel()の単純なif / elseで簡単に実行できると思いますが、Parcelとしてパラメーターを受け取るクラスのコンストラクターで同じことを実行する方法です。次のように
private Student(Parcel in) {
}
null値の送信中にいくつかの問題があります。
編集:追加されたコード
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeString(name);
dest.writeString(grade);
dest.writeString(dateOfBirth);
dest.writeString(place);
//Like wise there are many other fields
//We have to write only values which are not null
}
private Student(Parcel in) {
id=in.readString();
name=in.readString();
grade=in.readString();
dateOfBirth=in.readString();
place=in.readString();
//like wise have to read all other fields
//we have to make sure we read only values which are not null
}