Marshall a parcelable object to a byte array - Android Android OS

Android examples for Android OS:Parcel

Description

Marshall a parcelable object to a byte array

Demo Code


//package com.java2s;
import android.os.Parcel;
import android.os.Parcelable;

public class Main {
    /**/*from  w  w  w.j  a va  2 s. c  om*/
     * Marshall a parcelable object to a byte array
     * @param parceable
     * @return
     */
    public static byte[] marshall(Parcelable parceable) {
        Parcel parcel = Parcel.obtain();
        parceable.writeToParcel(parcel, 0);
        byte[] bytes = parcel.marshall();
        parcel.recycle(); // not sure if needed or a good idea
        return bytes;
    }
}

Related Tutorials