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?
Bundle is a container for named values of types standard for android (including Parcelable ), which is used to pass data between activies, fragments and other android app entites.
Parcelable and Bundle objects are intended to be used across process boundaries such as with IPC/Binder transactions, between activities with intents, and to store transient state across configuration changes.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With