Code example for Parcel

Methods: dataPosition, setDataPosition, writeBooleanArray, writeByte, 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 (localDetailID != null) {
            validDataList[MemberData.LOCAL_DETAIL_ID.ordinal()] = true;
            dest.writeLong(localDetailID); // Primary key in database
        } 
 
        if (localContactID != null) {
            validDataList[MemberData.LOCAL_CONTACT_ID.ordinal()] = true;
            dest.writeLong(localContactID);
        } 
 
        if (key != null) {
            validDataList[MemberData.KEY.ordinal()] = true;
            dest.writeInt(key.ordinal());
        } 
 
        if (keyType != null) {
            validDataList[MemberData.KEY_TYPE.ordinal()] = true;
            dest.writeInt(keyType.ordinal());
        } 
 
        if (value != null) {
            validDataList[MemberData.VALUE.ordinal()] = true;
            dest.writeString(value);
        } 
 
        if (deleted != null) {
            validDataList[MemberData.DELETED.ordinal()] = true;
            dest.writeByte((byte)(deleted ? 1 : 0));
        } 
 
        if (updated != null) {
            validDataList[MemberData.UPDATED.ordinal()] = true;
            dest.writeLong(updated);
        } 
 
        if (unique_id != null) {
            validDataList[MemberData.UNIQUE_ID.ordinal()] = true;
            dest.writeLong(unique_id);
        } 
 
        if (order != null) {
            validDataList[MemberData.ORDER.ordinal()] = true;
            dest.writeInt(order);
        } 
 
        if (location != null) {
            validDataList[MemberData.LOCATION.ordinal()] = true;
            location.writeToParcel(dest, 0);
        } 
 
        if (alt != null) {
            validDataList[MemberData.ALT.ordinal()] = true;
            dest.writeString(alt);
        } 
 
        if (photo != null) {
            validDataList[MemberData.PHOTO.ordinal()] = true;
            photo.writeToParcel(dest, 0);
        } 
 
        if (photo_mime_type != null) {
            validDataList[MemberData.PHOTO_MIME_TYPE.ordinal()] = true;
            dest.writeString(photo_mime_type);
        } 
 
        if (photo_url != null) {
            validDataList[MemberData.PHOTO_URL.ordinal()] = true;
            dest.writeString(photo_url);
        } 
 
        if (serverContactId != null) {
            validDataList[MemberData.SERVER_CONTACT_ID.ordinal()] = true;
            dest.writeLong(serverContactId);
        } 
 
        if (nativeContactId != null) {
            validDataList[MemberData.NATIVE_CONTACT_ID.ordinal()] = true;
            dest.writeInt(nativeContactId);
        } 
 
        if (nativeDetailId != null) {
            validDataList[MemberData.NATIVE_DETAIL_ID.ordinal()] = true;
            dest.writeInt(nativeDetailId);
        } 
 
        if (nativeVal1 != null) {
            validDataList[MemberData.NATIVE_VAL1.ordinal()] = true;
            dest.writeString(nativeVal1);
        } 
 
        if (nativeVal2 != null) {
            validDataList[MemberData.NATIVE_VAL2.ordinal()] = true;
            dest.writeString(nativeVal2);
        } 
 
        if (nativeVal3 != null) {
            validDataList[MemberData.NATIVE_VAL3.ordinal()] = true;
            dest.writeString(nativeVal3);
        } 
 
        int currentPos = dest.dataPosition();
        dest.setDataPosition(validDataPos);
        dest.writeBooleanArray(validDataList); // real array
        dest.setDataPosition(currentPos);
    } 
 
    /** 
     * Interface to allow ContactDetail to be written and restored from a 
     * Parcel.