Example usage for android.os Parcel recycle

List of usage examples for android.os Parcel recycle

Introduction

In this page you can find the example usage for android.os Parcel recycle.

Prototype

public final void recycle() 

Source Link

Document

Put a Parcel object back into the pool.

Usage

From source file:Main.java

public static byte[] toByteArray(Spanned spanned) {
    Parcel obtain = Parcel.obtain();
    TextUtils.writeToParcel(spanned, obtain, 0);
    byte[] byteArray = obtain.marshall();
    obtain.recycle();
    return byteArray;
}

From source file:Main.java

public static Bundle bundleFromByteArray(byte[] byteArray) {
    Parcel obtain = Parcel.obtain();
    obtain.unmarshall(byteArray, 0, byteArray.length);
    obtain.setDataPosition(0);//ww w.jav  a 2s  .c om
    Bundle result = Bundle.CREATOR.createFromParcel(obtain);
    obtain.recycle();
    return result;
}

From source file:Main.java

public static <T extends Parcelable> T clone(final T original, final Parcelable.Creator<T> creator) {
    final Parcel parcel = Parcel.obtain();
    original.writeToParcel(parcel, 0);//from ww w. j  a v  a2 s  . co  m
    parcel.setDataPosition(0);
    final T copy = creator.createFromParcel(parcel);
    parcel.recycle();
    return copy;
}

From source file:Main.java

public static Intent intentFromByteArray(byte[] byteArray) {
    Parcel obtain = Parcel.obtain();
    obtain.unmarshall(byteArray, 0, byteArray.length);
    obtain.setDataPosition(0);/*from  ww  w .  j  a v a 2 s .  co  m*/
    Intent createFromParcel = Intent.CREATOR.createFromParcel(obtain);
    obtain.recycle();
    return createFromParcel;
}

From source file:Main.java

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

From source file:Main.java

public static ContentValues contentValuesFromByteArray(byte[] byteArray) {
    Parcel obtain = Parcel.obtain();
    obtain.unmarshall(byteArray, 0, byteArray.length);
    obtain.setDataPosition(0);//from w  w  w  .  ja  v a  2 s  .c  o  m
    ContentValues createFromParcel = ContentValues.CREATOR.createFromParcel(obtain);
    obtain.recycle();
    return createFromParcel;
}

From source file:org.gearvrf.weartouchpad.MessageListenerService.java

private static <T> T unmarshall(byte[] bytes, Parcelable.Creator<T> creator) {
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);//from   ww w.  ja  v a 2s .  c o  m
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}

From source file:Main.java

public static Spanned spannedFromByteArray(byte[] byteArray) {
    Parcel obtain = Parcel.obtain();
    obtain.unmarshall(byteArray, 0, byteArray.length);
    obtain.setDataPosition(0);//  w ww.  j  a  v a2s  . c  o m
    Spanned result = (Spanned) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(obtain);
    obtain.recycle();
    return result;
}

From source file:Main.java

public static Bundle fromBase64(String serialized) {
    Bundle bundle = null;/*w  w  w  .jav a 2  s  . co m*/
    if (serialized != null) {
        Parcel parcel = Parcel.obtain();
        try {
            byte[] data = Base64.decode(serialized, 0);
            parcel.unmarshall(data, 0, data.length);
            parcel.setDataPosition(0);
            bundle = parcel.readBundle();
        } finally {
            parcel.recycle();
        }
    }
    return bundle;
}

From source file:Main.java

public static Bundle mutate(Bundle bundle) {

    if (bundle == null) {
        return null;
    }/*from  w  w  w . j a va  2  s  .c  o m*/

    final Parcel in = Parcel.obtain();
    in.writeBundle(bundle);
    final byte[] bytes = in.marshall();

    final Parcel out = Parcel.obtain();
    out.unmarshall(bytes, 0, bytes.length);
    out.setDataPosition(0);

    try {
        return out.readBundle();
    } finally {
        in.recycle();
        out.recycle();
    }
}