为什么Android Studio的自动Parcelable实现中忽略了java.lang.Integer?

时间:2017-01-27 17:30:14

标签: android android-studio parcelable

这是Android Studio生成的自动Parcelable实现。不知何故,它总是忽略类型为resultCode

Integer
public class TestParceable implements Parcelable {

        private String message;
        private Integer resultCode; //an Integer   

    protected TestParceable(Parcel in) {
        message = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(message);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<TestParceable> CREATOR = new Creator<TestParceable>() {
        @Override
        public TestParceable createFromParcel(Parcel in) {
            return new TestParceable(in);
        }

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

另一方面,如果我将resultCode的类型更改为int,则自动Parcelable实现会考虑它。

public class TestParceable implements Parcelable {

        private String message;
        private int resultCode; //an int

protected TestParceable(Parcel in) {
    message = in.readString();
    resultCode = in.readInt();
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(message);
    dest.writeInt(resultCode);
}

@Override
public int describeContents() {
    return 0;
}

public static final Creator<TestParceable> CREATOR = new Creator<TestParceable>() {
    @Override
    public TestParceable createFromParcel(Parcel in) {
        return new TestParceable(in);
    }

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

我在这里遗漏了什么,或者这是Android Studio的错误吗?

1 个答案:

答案 0 :(得分:0)

这是一个针对Studio 2.4修复的错误(https://code.google.com/p/android/issues/detail?id=233034)。