Code example for Parcel

Methods: dataPosition, setDataPosition, writeBooleanArray, writeByte, 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 (mFullname != null) {
            validDataList[MemberData.FULLNAME.ordinal()] = true;
            dest.writeString(mFullname);
        } 
 
        if (mUsername != null) {
            validDataList[MemberData.USERNAME.ordinal()] = true;
            dest.writeString(mUsername);
        } 
 
        if (mPassword != null) {
            validDataList[MemberData.PASSWORD.ordinal()] = true;
            dest.writeString(mPassword);
        } 
 
        if (mEmail != null) {
            validDataList[MemberData.EMAIL.ordinal()] = true;
            dest.writeString(mEmail);
        } 
 
        if (mBirthdayDate != null) {
            validDataList[MemberData.BIRTHDAY_DATE.ordinal()] = true;
            dest.writeString(mBirthdayDate);
        } 
 
        if (mMsisdn != null) {
            validDataList[MemberData.MSISDN.ordinal()] = true;
            dest.writeString(mMsisdn);
        } 
 
        if (mAcceptedTAndC != null) {
            validDataList[MemberData.ACCEPTED_T_AND_C.ordinal()] = true;
            dest.writeByte((byte)(mAcceptedTAndC ? 1 : 0));
        } 
 
        if (mCountrycode != null) {
            validDataList[MemberData.COUNTRY_CODE.ordinal()] = true;
            dest.writeString(mCountrycode);
        } 
 
        if (mTimezone != null) {
            validDataList[MemberData.TIME_ZONE.ordinal()] = true;
            dest.writeString(mTimezone);
        } 
 
        if (mLanguage != null) {
            validDataList[MemberData.LANGUAGE.ordinal()] = true;
            dest.writeString(mLanguage);
        } 
 
        if (mMobileOperatorId != null) {
            validDataList[MemberData.MOBILE_OPERATOR_ID.ordinal()] = true;
            dest.writeLong(mMobileOperatorId);
        } 
 
        if (mMobileModelId != null) {
            validDataList[MemberData.MOBILE_MODEL_ID.ordinal()] = true;
            dest.writeLong(mMobileModelId);
        } 
 
        if (mSendConfirmationMail != null) {
            validDataList[MemberData.SEND_CONFIRMATION_MAIL.ordinal()] = true;
            dest.writeByte((byte)(mSendConfirmationMail ? 1 : 0));
        } 
 
        if (mSendConfirmationSms != null) {
            validDataList[MemberData.SEND_CONFIRMATION_SMS.ordinal()] = true;
            dest.writeByte((byte)(mSendConfirmationSms ? 1 : 0));
        } 
 
        if (mSubscribeToNewsLetter != null) {
            validDataList[MemberData.SUBSCRIBE_TO_NEWSLETTER.ordinal()] = true;
            dest.writeByte((byte)(mSubscribeToNewsLetter ? 1 : 0));
        } 
 
        int currentPos = dest.dataPosition();
        dest.setDataPosition(validDataPos);
        dest.writeBooleanArray(validDataList); // Real array.
        dest.setDataPosition(currentPos);
    } 
 
    /*** 
     * Parcelable creator for RegistrationDetails. 
     */