get Parcelable Object - Android Android OS

Android examples for Android OS:Parcel

Description

get Parcelable Object

Demo Code


//package com.java2s;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

public class Main {
    public static <T> T getParcelable(@NonNull byte[] bytes,
            Parcelable.Creator<T> creator) {
        if (bytes == null || creator == null) {
            return null;
        }/*from   w  w  w  .  j  a va  2 s . c  om*/
        return creator.createFromParcel(unmarshall(bytes));
    }

    private static Parcel unmarshall(byte[] bytes) {
        Parcel parcel = Parcel.obtain();
        parcel.unmarshall(bytes, 0, bytes.length);
        parcel.setDataPosition(0);
        return parcel;
    }
}

Related Tutorials