Get ArrayList from Bundle by key - Android android.os

Android examples for android.os:Bundle

Description

Get ArrayList from Bundle by key

Demo Code

import java.util.ArrayList;
import java.util.Arrays;

import android.os.Bundle;
import android.os.Parcelable;

public class Main {

  @SuppressWarnings("unchecked")
  public static <T extends Parcelable> ArrayList<T> getArrayList(Bundle bundle, String key) {
    if (bundle == null) {
      return null;
    }//w  w w. j  a va  2s  .com
    Object o = bundle.get(key);
    try {
      return (ArrayList<T>) o;
    } catch (ClassCastException e) {
      try {
        return new ArrayList<T>(Arrays.asList((T[]) o));
      } catch (ClassCastException e2) {

        return null;
      }
    }
  }

}

Related Tutorials