2017-08-24 6 views
1

私はParcelableオブジェクトのリストを持つParcelableオブジェクトを持っています。私はそれが次への1つのActivityから渡されたバック後にそのリストを読み込むしようとしていますが、唯一の最初の要素は、「アンバンドル」リストで区切ります。最初の要素は除外されます。

public class MyBundle implements Parcelable { 
    private List<Data> dataList; 

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

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

    public MyBundle() { 
    } 

    public MyBundle(Parcel in) { 
     //dataList = new ArrayList<>(); 
     //in.readTypedList(dataList, Data.CREATOR); 
     dataList = in.createTypedArrayList(Data.CREATOR); 
     //BOTH have the same result 
    } 

    @Override 
    public int describeContents() { 
     return 0; 
    } 

    @Override 
    public void writeToParcel(Parcel dest, int flags) { 
     if (dataList != null && dataList.size() > 0) { 
      dest.writeTypedList(dataList); 
     } 
    } 
} 

データオブジェクトです:

/*BaseObject has the following properties: 
    UUID uuid; 
    long databaseId; 
    createdDate; 
    modifiedDate; 
*/ 
public class Data extends BaseObject implements Parcelable { 
    private String name; 
    private String serial; 
    private String location; 

    public Data() {} 

    private Data(Parcel in) { 
     String uuidString = in.readString(); 
     if (uuidString == null) return; //this is null! 
     uuid = UUID.fromString(idString); 
     databaseId = in.readLong(); 
     createdDate = new Date(in.readLong()); 
     modifiedDate = new Date(in.readLong()); 
     location = in.readString(); 

     name = in.readString(); 
     serial = in.readString(); 
    } 

    @Override 
    public int describeContents() { 
     return 0; 
    } 

    @Override 
    public void writeToParcel(Parcel dest, int flags) { 
     dest.writeString(uuid.toString()); 
     dest.writeLong(databaseId); 
     dest.writeLong(createdDate.getTime()); 
     dest.writeLong(modifiedDate.getTime()); 

     dest.writeString(name); 
     dest.writeString(serial); 
    } 

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

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

何私が試してみました:

答えて

0

これが答えです:それは小包を作成するときにマイデータparcelableは、location要素をミス。 READINGが発生すると、これは明らかに何らかのオフセットエラーを引き起こします。コード化された解決策は次のとおりです。

@Override 
    public void writeToParcel(Parcel dest, int flags) { 
     dest.writeString(uuid.toString()); 
     dest.writeLong(databaseId); 
     dest.writeLong(createdDate.getTime()); 
     dest.writeLong(modifiedDate.getTime()); 
     dest.writeString(location); /*HERE!*/ 
     dest.writeString(name); 
     dest.writeString(serial); 
    } 

私はこれが他の人に役立つことを望みます。

関連する問題