Code example for Parcel

Methods: dataPosition, setDataPosition, writeArray, writeBooleanArray, writeByteArray, writeInt, writeLong, writeString

0
 
    /** {@inheritDoc} */ 
    @Override 
    public void writeToParcel(Parcel dest, int flags) {
        boolean[] validDataList = new boolean[MemberData.values().length];
        int validDataPos = dest.dataPosition();
        dest.writeBooleanArray(validDataList); // Placeholder for real array.
        if (mGroupType != null) {
            validDataList[MemberData.GROUP_TYPE.ordinal()] = true;
            dest.writeInt(mGroupType);
        } 
        final Boolean[] boolArray = new Boolean[4];
        if (mIsReadOnly != null) {
            validDataList[MemberData.IS_READ_ONLY.ordinal()] = true;
            boolArray[0] = mIsReadOnly;
        } 
        if (mRequiresLocalisation != null) {
            validDataList[MemberData.REQUIRES_LOCALISATION.ordinal()] = true;
            boolArray[1] = mRequiresLocalisation;
        } 
        if (mIsSystemGroup != null) {
            validDataList[MemberData.IS_SYSTEM_GROUP.ordinal()] = true;
            boolArray[2] = mIsSystemGroup;
        } 
        if (mIsSmartGroup != null) {
            validDataList[MemberData.IS_SMART_GROUP.ordinal()] = true;
            boolArray[3] = mIsSmartGroup;
        } 
        dest.writeArray(boolArray);
        if (mLocalGroupId != null) {
            validDataList[MemberData.LOCAL_GROUP_ID.ordinal()] = true;
            dest.writeLong(mLocalGroupId);
        } 
        if (mId != null) {
            validDataList[MemberData.ID.ordinal()] = true;
            dest.writeLong(mId);
        } 
        if (mUserId != null) {
            validDataList[MemberData.USER_ID.ordinal()] = true;
            dest.writeLong(mUserId);
        } 
        if (mName != null) {
            validDataList[MemberData.NAME.ordinal()] = true;
            dest.writeString(mName);
        } 
        if (mImageMimeType != null) {
            validDataList[MemberData.IMAGE_MIME_TYPE.ordinal()] = true;
            dest.writeString(mImageMimeType);
        } 
        if (mImageBytes != null) {
            validDataList[MemberData.IMAGE_BYTES.ordinal()] = true;
            dest.writeByteArray(mImageBytes.array());
        } 
        if (mColor != null) {
            validDataList[MemberData.COLOR.ordinal()] = true;
            dest.writeString(mColor);
        } 
        int currentPos = dest.dataPosition();
        dest.setDataPosition(validDataPos);
        dest.writeBooleanArray(validDataList); // Real array.
        dest.setDataPosition(currentPos);
    } 
}