Problem unmarshalling parcelables

后端 未结 10 1922
旧时难觅i
旧时难觅i 2020-11-27 15:45

I\'ve got a few classes that implement Parcelable and some of these classes contain each other as properties. I\'m marshalling the classes into a Parcel to pass them between

10条回答
  •  攒了一身酷
    2020-11-27 16:04

    Well I had the same problem and solve it in a very silly way that I dont know if its called a solution at all.

    lets say you have this class you want to pass to another activity

    public class Person implements  Parcelable,Serializable{
    public  String Name;
    public  int Age;
    
    @Override
    public void writeToParcel(Parcel dest, int flags) {
    
     dest.writeString(name);
    dest.writeInt(age);
    
    }
    
    public SeriesInfo(Parcel in) {
    
    age= in.readInt(); //her was my problem as I have put age befor name
    //while in the writeToParcel function I have defined
    //dest.writeInt(age) after  in.readString();???!!!!
    name= in.readString();
    
    }
    }
    

    Thats it When I changed the:

    dest.writeString(name);
    dest.writeInt(age);
    

    to

    dest.writeInt(age);
    dest.writeString(name);
    

    The problem was solved???!!!!

提交回复
热议问题