Some package objects collected in the Intent / bundle can interfere with and compromise the reading of the Intent / Bundle?

Some package objects gathered together in an Intent / bundle can interfere with and compromise the reading of an Intent / Bundle?

I am retrieving 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 another complex batch object (using the multidimensional ArrayList array):

 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 get a boucle with over 10,000,000 elements for arraylist1 (or other issues are not clear)

though, 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 create an object that extends ArrayList and implements Parcelable, but I have some other problems (like android.os.BadParcelableException: ClassNotFoundException when unmarshalling :)

If these objects get in the way, so should I use multiple packages so that these different objects are in the same intent?

+6
source share
1 answer

I think one day I had the same problem. As far as I remember, I fixed this by writing / reading Parcelable always after all other types. Sort of:

 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()); } 

(Didn't try this code though)

+7
source

Source: https://habr.com/ru/post/887812/


All Articles