Bad magic number for Bundle in Android

后端 未结 5 1569
挽巷
挽巷 2020-12-18 22:16

I\'m passing data from one activity to other activity with this code:

 @Override
    public void execute(List reports, Questions question) {
           


        
5条回答
  •  悲&欢浪女
    2020-12-18 22:32

    To be honest with you, i never got such of error. But i use a different way to store a list of parcelable (QuestionsGroup) inside my parcelable (Questions) :

       private Questions(Parcel in) {
            this();
            this.idReport = in.readInt();
            this.nameReport = in.readString();
            this.replyGroups = in.readString();
            //Bundle b = in.readBundle(QuestionsGroup.class.getClassLoader());
            //this.questionsGroup = b.getParcelableArrayList("questionGroups");
            this.questionsGroup = in.readTypedList(questionsGroup,QuestionsGroup.CREATOR);
            this.canCreateNew = (Boolean) in.readValue(Boolean.class.getClassLoader());
        }
    

    And :

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.idReport);
        dest.writeString(this.nameReport);
        dest.writeString(this.replyGroups);
        //Bundle b = new Bundle();
        //b.putParcelableArrayList("questionGroups", (ArrayList) this.questionsGroup);
        //dest.writeBundle(b);
        dest.writeTypedList(questionsGroup);
        dest.writeValue(this.canCreateNew);
    }
    

    I use above's code in my projects and its working fine. You might want to try it since its easy and fast.

提交回复
热议问题