-1
私のandroid app用私はアプリケーションがbrackgroundにあるときにデータを保存するparcelableインターフェイスを使用したいと思います。私はクラスに3つの浮動小数点数を持っています。PojoのParcelableインターフェイスを使用して
それは動作しますが、私のアプリケーションを起動すると値が混ざります。つまり、3番目のfloat属性の値が最初の値になります。デュランダルが言ったように、あなたはあなたが小包にアクセスするときにそれらを取得したい正確な順序を指定する必要が
public class Lunch implements Parcelable {
private String mName;
private float priceStud;
private float priceEmp;
private float priceGuest;
private ArrayList<Lunch> m = new ArrayList<Lunch>();
public static final int PRICE_STUDENT = 0;
public static final int PRICE_EMPLOYEE = 1;
public static int PRICE_GUEST = 2;
public Lunch(Parcel in) {
setmName(in.readString());
setPriceStud(in.readFloat());
setPriceEmp(in.readFloat());
setPriceGuest(in.readFloat());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(getmName());
dest.writeFloat(getPriceGuest());
dest.writeFloat(getPriceEmp());
dest.writeFloat(getPriceStud());
}
public static final Creator<Lunch> CREATOR = new Creator<Lunch>() {
public Lunch createFromParcel(Parcel in) {
return new Lunch(in);
}
public Lunch[] newArray(int size) {
return new Lunch[size];
}
};
明らかに、書き込んだのと同じ順序で値を読み取る必要があります。 – Durandal
@Durandalありがとうございました。私はこれをずっと無視していた – herres