Code example for Parcel

Methods: dataPosition, setDataPosition, writeBooleanArray, writeByteArray, writeInt, 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 (mExponential != null) {
            validDataList[MemberData.EXPONENTIAL.ordinal()] = true;
            dest.writeInt(mExponential.length);
            dest.writeByteArray(mExponential);
        } 
        if (mModulus != null) {
            validDataList[MemberData.MODULUS.ordinal()] = true;
            dest.writeInt(mModulus.length);
            dest.writeByteArray(mModulus);
        } 
        if (mKeyBase64 != null) {
            validDataList[MemberData.KEYBASE64.ordinal()] = true;
            dest.writeString(mKeyBase64);
        } 
        if (mKeyX509 != null) {
            validDataList[MemberData.KEYX509.ordinal()] = true;
            dest.writeInt(mKeyX509.length);
            dest.writeByteArray(mKeyX509);
        } 
        int currentPos = dest.dataPosition();
        dest.setDataPosition(validDataPos);
        dest.writeBooleanArray(validDataList); // Real array.
        dest.setDataPosition(currentPos);
    } 
}