PersistableBundlepublic final class PersistableBundle extends BaseBundle implements XmlUtils.WriteMapCallback, Cloneable, ParcelableA 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.
super(capacity);
| public PersistableBundle(PersistableBundle b)Constructs a PersistableBundle containing a copy of the mappings from the given
PersistableBundle.
super(b);
| private PersistableBundle(Map map)Constructs a PersistableBundle containing the mappings passed in.
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.Object | clone()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 int | describeContents()Report the nature of this Parcelable's contents
return 0;
| public static android.os.PersistableBundle | forPair(java.lang.String key, java.lang.String value)Make a PersistableBundle for a single key/value pair.
PersistableBundle b = new PersistableBundle(1);
b.putString(key, value);
return b;
| public android.os.PersistableBundle | getPersistableBundle(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.
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 void | putPersistableBundle(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.
unparcel();
mMap.put(key, value);
| public static android.os.PersistableBundle | restoreFromXml(org.xmlpull.v1.XmlPullParser in)
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 void | saveToXml(org.xmlpull.v1.XmlSerializer out)
unparcel();
XmlUtils.writeMapXml(mMap, out, this);
| public synchronized java.lang.String | toString()
if (mParcelledData != null) {
if (mParcelledData == EMPTY_PARCEL) {
return "PersistableBundle[EMPTY_PARCEL]";
} else {
return "PersistableBundle[mParcelledData.dataSize=" +
mParcelledData.dataSize() + "]";
}
}
return "PersistableBundle[" + mMap.toString() + "]";
| public void | writeToParcel(Parcel parcel, int flags)Writes the PersistableBundle contents to a Parcel, typically in order for
it to be passed through an IBinder connection.
final boolean oldAllowFds = parcel.pushAllowFds(false);
try {
writeToParcelInner(parcel, flags);
} finally {
parcel.restoreAllowFds(oldAllowFds);
}
| public void | writeUnknownObject(java.lang.Object v, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
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);
}
|
|