iielse / switchbutton

iOS风格SwitchButton。 只涉及到一个类文件,异常容易集成进入你的项目。支持开关的"延时和回滚"操作。only one class file, very easy to integrate into your program. support the delay operation and rolling back action of the switch
677 stars 192 forks source link

Parcel android.os.Parcel@7c1d390: Unmarshalling unknown type code 2131296439 at offset 1204 #10

Closed g19980115 closed 6 years ago

g19980115 commented 7 years ago

大神啊,Parcel 写法不规范,我找了一个上午的问题... 在部分低内存的手机会出现这个情况,可以在开发者选项打开不保留活动模拟低内存 添加describeContents和CREATOR 可以解决问题 完整修改如下:

 static final class SavedState extends BaseSavedState {
        private boolean isOpened;

        SavedState(Parcelable superState) {
            super(superState);
        }

        private SavedState(Parcel in) {
            super(in);
            isOpened = 1 == in.readInt();
        }

        @Override
        public void writeToParcel(Parcel out, int flags) {
            super.writeToParcel(out, flags);
            out.writeInt(isOpened ? 1 : 0);
        }

        //必须
        @Override
        public int describeContents() {
            return 0;
        }
        //必须
        public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
            @Override
            public SavedState createFromParcel(Parcel in) {
                return new SavedState(in);
            }

            @Override
            public SavedState[] newArray(int size) {
                return new SavedState[size];
            }
        };
    }