Example usage for android.os Parcelable writeToParcel

List of usage examples for android.os Parcelable writeToParcel

Introduction

In this page you can find the example usage for android.os Parcelable writeToParcel.

Prototype

public void writeToParcel(Parcel dest, @WriteFlags int flags);

Source Link

Document

Flatten this object in to a Parcel.

Usage

From source file:Main.java

public static byte[] serialize(Parcelable parceable) {
    Parcel parcel = Parcel.obtain();/*from  w w w  . ja v a2s.c o  m*/
    parceable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}

From source file:Main.java

public static byte[] marshall(Parcelable parcelable) {
    Parcel parcel = Parcel.obtain();/*from  w ww  .j  a  v  a 2s. c  o  m*/

    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();

    return bytes;
}

From source file:Main.java

private static byte[] parcelable2Bytes(final Parcelable parcelable) {
    if (parcelable == null)
        return null;
    Parcel parcel = Parcel.obtain();/* w  w w  .  j  a va2  s .  co m*/
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}

From source file:Main.java

public static byte[] getBytes(@NonNull Parcelable parcelable) {
    if (parcelable == null) {
        return new byte[0];
    }/* w w  w.j  ava  2s.c o m*/
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
protected void onRestoreInstanceState(Parcelable state) {
    SavedState ss = null;/*from www  . j av  a 2 s.  c om*/
    if (state.getClass().getClassLoader() != getClass().getClassLoader()) {
        // Class loader mismatch, recreate from parcel.
        Parcel stateParcel = Parcel.obtain();
        state.writeToParcel(stateParcel, 0);
        ss = SavedState.CREATOR.createFromParcel(stateParcel);
    } else {
        ss = (SavedState) state;
    }
    super.onRestoreInstanceState(ss.getSuperState());

    if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
        openDrawer();
    }

    setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
    setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
}