开发者

Some parcelables objects put together in an Intent/bundle could be interfere themselves and to compromise the read of Intent/Bundle?

Some parcelables objects put together in an Intent/bundle could be interfere themselves and to compromise the read of Intent/Bundle?

I extract the code where, i think, there is a problem. This code works:

public void writeToParcel(Parcel arg0, int arg1) {
    arg0.writeParcelable(object1, arg1);
    arg0.writeTypedList(arraylist1); 

}

public void readFromParcel(Parcel in) {
    object1  = in.readParcelable(object1.class.getClassLoader());
    arraylist1 = new ArrayList<object3>();
    in.readTypedList(arraylist1, object3.CREATOR);
   }

but if I add an other complex parcelable object (with intern parcelable ArrayList):

public void writeToParcel(Parcel arg0, int arg1) {
    arg0.writeParcelable(object1, arg1);
    arg0.writeParcelable(object2, arg1);
    arg0.writeTypedList(arraylist1); 

}

public void readFromParcel(Parcel in) {
    object1  = in.readParcelable(object1.class.getClassLoader());
    object2 = in.readParcelable(object2.class.getClassLoader());
    arraylist1 = new ArrayList<object3>();
    in.readTypedList(arraylist1, object3.CREATOR);
   }

I obtain an boucle with more 10000000 elements for arraylist1 (or others issues incomprehensible)

although if I delete lines with arraylist1, it works:

public void writeToParcel(开发者_运维百科Parcel arg0, int arg1) {
    arg0.writeParcelable(this.object1, arg1);
    arg0.writeParcelable(this.object2, arg1); 

}

public void readFromParcel(Parcel in) {
    object1  = in.readParcelable(object1.class.getClassLoader());
    object2 = in.readParcelable(object2.class.getClassLoader());
   } 

I tried to make an object that extends ArrayList and implements Parcelable but I have some others issues (as android.os.BadParcelableException: ClassNotFoundException when unmarshalling:)

If these object interfere themselves, so I have to use several bundles tu put these different objects into a same intent?


I think I had the same problem one day. As far as I can remember, I fixed it by writing/reading Parcelable always after all other types. Something like:

public void writeToParcel(Parcel arg0, int arg1) {
    arg0.writeTypedList(arraylist1); 

    arg0.writeParcelable(object1, arg1);
    arg0.writeParcelable(object2, arg1);
}

public void readFromParcel(Parcel in) {
    arraylist1 = new ArrayList<object3>();
    in.readTypedList(arraylist1, object3.CREATOR);

    object1  = in.readParcelable(object1.class.getClassLoader());
    object2 = in.readParcelable(object2.class.getClassLoader());
}

(Haven't tried this code though)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜