Code example for Parcel

Methods: dataPosition, setDataPosition, writeBooleanArray, writeByte, 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 (mUsername != null) {
            validDataList[MemberData.USERNAME.ordinal()] = true;
            dest.writeString(mUsername);
        } 
 
        if (mPassword != null) {
            validDataList[MemberData.PASSWORD.ordinal()] = true;
            dest.writeString(mPassword);
        } 
 
        if (mMobileNo != null) {
            validDataList[MemberData.MOBILE_NO.ordinal()] = true;
            dest.writeString(mMobileNo);
        } 
 
        if (mSubscriberId != null) {
            validDataList[MemberData.SUBSCRIBER_ID.ordinal()] = true;
            dest.writeString(mSubscriberId);
        } 
 
        dest.writeByte((byte)(mRememberMe ? 1 : 0));
        dest.writeByte((byte)(mAutoConnect ? 1 : 0));
 
        int currentPos = dest.dataPosition();
        dest.setDataPosition(validDataPos);
        dest.writeBooleanArray(validDataList); // real array
        dest.setDataPosition(currentPos);
    } 
 
    /*** 
     * Parcelable constructor for LoginDetails. 
     *