package com.fsck.k9.helper; import android.os.Parcel; import android.os.Parcelable; // Source: http://stackoverflow.com/a/18000094 public class ParcelableUtil { public static byte[] marshall(Parcelable parceable) { Parcel parcel = Parcel.obtain(); parceable.writeToParcel(parcel, 0); byte[] bytes = parcel.marshall(); parcel.recycle(); return bytes; } public static <T> T unmarshall(byte[] bytes, Parcelable.Creator<T> creator) { Parcel parcel = unmarshall(bytes); T result = creator.createFromParcel(parcel); parcel.recycle(); return result; } private static Parcel unmarshall(byte[] bytes) { Parcel parcel = Parcel.obtain(); parcel.unmarshall(bytes, 0, bytes.length); parcel.setDataPosition(0); return parcel; } }