FileDocCategorySizeDatePackage
PersistableBundle.javaAPI DocAndroid 5.1 API8871Thu Mar 12 22:22:10 GMT 2015android.os

PersistableBundle

public final class PersistableBundle extends BaseBundle implements XmlUtils.WriteMapCallback, Cloneable, Parcelable
A mapping from String values to various types that can be saved to persistent and later restored.

Fields Summary
private static final String
TAG_PERSISTABLEMAP
public static final PersistableBundle
EMPTY
static final Parcel
EMPTY_PARCEL
public static final Parcelable.Creator
CREATOR
Constructors Summary
public PersistableBundle()
Constructs a new, empty PersistableBundle.


     
        EMPTY = new PersistableBundle();
        EMPTY.mMap = ArrayMap.EMPTY;
        EMPTY_PARCEL = BaseBundle.EMPTY_PARCEL;
    
        super();
    
public PersistableBundle(int capacity)
Constructs a new, empty PersistableBundle sized to hold the given number of elements. The PersistableBundle will grow as needed.

param
capacity the initial capacity of the PersistableBundle

        super(capacity);
    
public PersistableBundle(PersistableBundle b)
Constructs a PersistableBundle containing a copy of the mappings from the given PersistableBundle.

param
b a PersistableBundle to be copied.

        super(b);
    
private PersistableBundle(Map map)
Constructs a PersistableBundle containing the mappings passed in.

param
map a Map containing only those items that can be persisted.
throws
IllegalArgumentException if any element of #map cannot be persisted.

        super();

        // First stuff everything in.
        putAll(map);

        // Now verify each item throwing an exception if there is a violation.
        Set<String> keys = map.keySet();
        Iterator<String> iterator = keys.iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object value = map.get(key);
            if (value instanceof Map) {
                // Fix up any Maps by replacing them with PersistableBundles.
                putPersistableBundle(key, new PersistableBundle((Map<String, Object>) value));
            } else if (!(value instanceof Integer) && !(value instanceof Long) &&
                    !(value instanceof Double) && !(value instanceof String) &&
                    !(value instanceof int[]) && !(value instanceof long[]) &&
                    !(value instanceof double[]) && !(value instanceof String[]) &&
                    !(value instanceof PersistableBundle) && (value != null) &&
                    !(value instanceof Boolean) && !(value instanceof boolean[])) {
                throw new IllegalArgumentException("Bad value in PersistableBundle key=" + key +
                        " value=" + value);
            }
        }
    
PersistableBundle(Parcel parcelledData, int length)

        super(parcelledData, length);
    
Methods Summary
public java.lang.Objectclone()
Clones the current PersistableBundle. The internal map is cloned, but the keys and values to which it refers are copied by reference.

        return new PersistableBundle(this);
    
public intdescribeContents()
Report the nature of this Parcelable's contents

        return 0;
    
public static android.os.PersistableBundleforPair(java.lang.String key, java.lang.String value)
Make a PersistableBundle for a single key/value pair.

hide

        PersistableBundle b = new PersistableBundle(1);
        b.putString(key, value);
        return b;
    
public android.os.PersistableBundlegetPersistableBundle(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a Bundle value, or null

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (PersistableBundle) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "Bundle", e);
            return null;
        }
    
public voidputPersistableBundle(java.lang.String key, android.os.PersistableBundle value)
Inserts a PersistableBundle value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a Bundle object, or null

        unparcel();
        mMap.put(key, value);
    
public static android.os.PersistableBundlerestoreFromXml(org.xmlpull.v1.XmlPullParser in)

hide

        final int outerDepth = in.getDepth();
        final String startTag = in.getName();
        final String[] tagName = new String[1];
        int event;
        while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
                (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
            if (event == XmlPullParser.START_TAG) {
                return new PersistableBundle((Map<String, Object>)
                        XmlUtils.readThisMapXml(in, startTag, tagName, new MyReadMapCallback()));
            }
        }
        return EMPTY;
    
public voidsaveToXml(org.xmlpull.v1.XmlSerializer out)

hide

        unparcel();
        XmlUtils.writeMapXml(mMap, out, this);
    
public synchronized java.lang.StringtoString()

        if (mParcelledData != null) {
            if (mParcelledData == EMPTY_PARCEL) {
                return "PersistableBundle[EMPTY_PARCEL]";
            } else {
                return "PersistableBundle[mParcelledData.dataSize=" +
                        mParcelledData.dataSize() + "]";
            }
        }
        return "PersistableBundle[" + mMap.toString() + "]";
    
public voidwriteToParcel(Parcel parcel, int flags)
Writes the PersistableBundle contents to a Parcel, typically in order for it to be passed through an IBinder connection.

param
parcel The parcel to copy this bundle to.

        final boolean oldAllowFds = parcel.pushAllowFds(false);
        try {
            writeToParcelInner(parcel, flags);
        } finally {
            parcel.restoreAllowFds(oldAllowFds);
        }
    
public voidwriteUnknownObject(java.lang.Object v, java.lang.String name, org.xmlpull.v1.XmlSerializer out)

hide


      
    
           
               
        if (v instanceof PersistableBundle) {
            out.startTag(null, TAG_PERSISTABLEMAP);
            out.attribute(null, "name", name);
            ((PersistableBundle) v).saveToXml(out);
            out.endTag(null, TAG_PERSISTABLEMAP);
        } else {
            throw new XmlPullParserException("Unknown Object o=" + v);
        }