put Parcelable List to Bundle - Android Android OS

Android examples for Android OS:Parcel

Description

put Parcelable List to Bundle

Demo Code


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

import java.util.ArrayList;
import java.util.List;

public class Main {
    @SuppressWarnings("unchecked")
    public static void putParcelableList(Bundle bundle,
            List<? extends Parcelable> list, String key) {
        if (list == null) {
            return;
        }/*from  w w w  .  ja v a  2 s  . c o  m*/
        ArrayList<? extends Parcelable> arrayList;
        if (list instanceof ArrayList) {
            arrayList = (ArrayList<? extends Parcelable>) list;
        } else {
            arrayList = new ArrayList<>(list);
        }

        bundle.putParcelableArrayList(key, arrayList);
    }
}

Related Tutorials