put value to Bundle - Android Android OS

Android examples for Android OS:Bundle Put

Description

put value to Bundle

Demo Code


//package com.book2s;
import android.os.Bundle;
import android.os.Parcelable;
import java.io.Serializable;
import java.util.ArrayList;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> void put(String key, Bundle bundle, T value) {
        if (value instanceof Serializable) {
            bundle.putSerializable(key, (Serializable) value);
        } else if (value instanceof Parcelable) {
            bundle.putParcelable(key, (Parcelable) value);
        } else if (value instanceof Parcelable[]) {
            bundle.putParcelableArray(key, (Parcelable[]) value);
        } else if (value instanceof ArrayList<?>) {
            bundle.putParcelableArrayList(key,
                    (ArrayList<? extends Parcelable>) value);
        } else if (value instanceof String[]) {
            bundle.putStringArray(key, (String[]) value);
        } else if (value instanceof String) {
            bundle.putString(key, (String) value);
        }//from w w  w.  j  av  a  2  s.co m
    }
}

Related Tutorials