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 <T> T unmarshall(byte[] bytes, Parcelable.Creator<T> creator) {
    Parcel parcel = unmarshall(bytes);

    T obj = creator.createFromParcel(parcel);
    parcel.recycle();

    return obj;/*from  w  ww.j  a  va  2  s  . c  o m*/
}

From source file:Main.java

public static byte[] serialize(Parcelable parceable) {
    Parcel parcel = Parcel.obtain();
    parceable.writeToParcel(parcel, 0);// w  w  w.java2s. com
    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();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}

From source file:Main.java

public static byte[] arrayToByteArray(ContentValues[] contentValues) {
    Parcel obtain = Parcel.obtain();
    obtain.writeParcelableArray(contentValues, 0);
    byte[] byteArray = obtain.marshall();
    obtain.recycle();
    return byteArray;
}

From source file:Main.java

public static byte[] marshall(Parcelable parcelable) {
    Parcel parcel = Parcel.obtain();

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

    return bytes;
}

From source file:Main.java

public static byte[] marshall(Object value) {
    if (value == null) {
        return null;
    }/*from   w ww .  j  a  v a  2s.c  om*/

    Parcel parcel = Parcel.obtain();
    try {
        parcel.writeValue(value);
        return parcel.marshall();
    } finally {
        parcel.recycle();
    }
}

From source file:Main.java

public static byte[] toByteArray(Bundle bundle) {
    Parcel obtain = Parcel.obtain();
    bundle.writeToParcel(obtain, 0);/* w w  w  .  j  a v a2 s . c  o  m*/
    byte[] byteArray = obtain.marshall();
    obtain.recycle();
    return byteArray;
}

From source file:Main.java

public static byte[] toByteArray(Intent intent) {
    Parcel obtain = Parcel.obtain();
    intent.writeToParcel(obtain, 0);/* ww w.j  a  va 2s.c o m*/
    byte[] byteArray = obtain.marshall();
    obtain.recycle();
    return byteArray;
}

From source file:Main.java

private static <T> T bytes2Parcelable(final byte[] bytes, final Parcelable.Creator<T> creator) {
    if (bytes == null)
        return null;
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);//from w w  w  .j a  v a  2 s  . c  om
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}

From source file:Main.java

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