PersistableBundle


public final class PersistableBundle
extends BaseBundle implements Cloneable, Parcelable

java.lang.Object
   ↳ android.os.BaseBundle
     ↳ android.os.PersistableBundle


A mapping from String keys to values of various types. The set of types supported by this class is purposefully restricted to simple objects that can safely be persisted to and restored from disk.

Warning: Note that PersistableBundle is a lazy container and as such it does NOT implement Object.equals(java.lang.Object) or Object.hashCode().

See also:

Summary

Inherited constants

int CONTENTS_FILE_DESCRIPTOR

Descriptor bit used with describeContents(): indicates that the Parcelable object's flattened representation includes a file descriptor.

int PARCELABLE_WRITE_RETURN_VALUE

Flag for use with writeToParcel(Parcel, int): the object being written is a return value, that is the result of a function such as "Parcelable someFunction()", "void someFunction(out Parcelable)", or "void someFunction(inout Parcelable)".

Fields

public static final Creator<PersistableBundle> CREATOR

public static final PersistableBundle EMPTY

An unmodifiable PersistableBundle that is always empty.

Public constructors

PersistableBundle()

Constructs a new, empty PersistableBundle.

PersistableBundle(PersistableBundle b)

Constructs a PersistableBundle containing a copy of the mappings from the given PersistableBundle.

PersistableBundle(int capacity)

Constructs a new, empty PersistableBundle sized to hold the given number of elements.

Public methods

Object clone()

Clones the current PersistableBundle.

PersistableBundle deepCopy()

Make a deep copy of the given bundle.

int describeContents()

Report the nature of this Parcelable's contents

PersistableBundle getPersistableBundle(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.

void putPersistableBundle(String key, PersistableBundle value)

Inserts a PersistableBundle value into the mapping of this Bundle, replacing any existing value for the given key.

static PersistableBundle readFromStream(InputStream inputStream)

Reads a PersistableBundle from an InputStream.

String toString()

Returns a string representation of the PersistableBundle that may be suitable for debugging.

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.

void writeToStream(OutputStream outputStream)

Writes the content of the PersistableBundle to a OutputStream.

Inherited methods

void clear()

Removes all elements from the mapping of this Bundle.

boolean containsKey(String key)

Returns true if the given key is contained in the mapping of this Bundle.

Object get(String key)

This method was deprecated in API level 33. Use the type-safe specific APIs depending on the type of the item to be retrieved, eg. getString(java.lang.String).

boolean getBoolean(String key, boolean defaultValue)

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

boolean getBoolean(String key)

Returns the value associated with the given key, or false if no mapping of the desired type exists for the given key.

boolean[] getBooleanArray(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.

double getDouble(String key, double defaultValue)

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

double getDouble(String key)

Returns the value associated with the given key, or 0.0 if no mapping of the desired type exists for the given key.

double[] getDoubleArray(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.

int getInt(String key)

Returns the value associated with the given key, or 0 if no mapping of the desired type exists for the given key.

int getInt(String key, int defaultValue)

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

int[] getIntArray(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.

long getLong(String key)

Returns the value associated with the given key, or 0L if no mapping of the desired type exists for the given key.

long getLong(String key, long defaultValue)

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

long[] getLongArray(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.

String getString(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.

String getString(String key, String defaultValue)

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key or if a null value is explicitly associated with the given key.

String[] getStringArray(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.

boolean isEmpty()

Returns true if the mapping of this Bundle is empty, false otherwise.

Set<String> keySet()

Returns a Set containing the Strings used as keys in this Bundle.

void putAll(PersistableBundle bundle)

Inserts all mappings from the given PersistableBundle into this BaseBundle.

void putBoolean(String key, boolean value)

Inserts a Boolean value into the mapping of this Bundle, replacing any existing value for the given key.

void putBooleanArray(String key, boolean[] value)

Inserts a boolean array value into the mapping of this Bundle, replacing any existing value for the given key.

void putDouble(String key, double value)

Inserts a double value into the mapping of this Bundle, replacing any existing value for the given key.

void putDoubleArray(String key, double[] value)

Inserts a double array value into the mapping of this Bundle, replacing any existing value for the given key.

void putInt(String key, int value)

Inserts an int value into the mapping of this Bundle, replacing any existing value for the given key.

void putIntArray(String key, int[] value)

Inserts an int array value into the mapping of this Bundle, replacing any existing value for the given key.

void putLong(String key, long value)

Inserts a long value into the mapping of this Bundle, replacing any existing value for the given key.

void putLongArray(String key, long[] value)

Inserts a long array value into the mapping of this Bundle, replacing any existing value for the given key.

void putString(String key, String value)

Inserts a String value into the mapping of this Bundle, replacing any existing value for the given key.

void putStringArray(String key, String[] value)

Inserts a String array value into the mapping of this Bundle, replacing any existing value for the given key.

void remove(String key)

Removes any entry with the given key from the mapping of this Bundle.

int size()

Returns the number of mappings contained in this Bundle.

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

abstract int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

abstract void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Fields

CREATOR

Added in API level 21
public static final Creator<PersistableBundle> CREATOR

EMPTY

Added in API level 21
public static final PersistableBundle EMPTY

An unmodifiable PersistableBundle that is always empty.

Public constructors

PersistableBundle

Added in API level 21
public PersistableBundle ()

Constructs a new, empty PersistableBundle.

PersistableBundle

Added in API level 21
public PersistableBundle (PersistableBundle b)

Constructs a PersistableBundle containing a copy of the mappings from the given PersistableBundle. Does only a shallow copy of the original PersistableBundle -- see deepCopy() if that is not what you want.

Parameters
b PersistableBundle: a PersistableBundle to be copied.

See also:

PersistableBundle

Added in API level 21
public PersistableBundle (int capacity)

Constructs a new, empty PersistableBundle sized to hold the given number of elements. The PersistableBundle will grow as needed.

Parameters
capacity int: the initial capacity of the PersistableBundle

Public methods

clone

Added in API level 21
public Object clone ()

Clones the current PersistableBundle. The internal map is cloned, but the keys and values to which it refers are copied by reference.

Returns
Object a clone of this instance.

deepCopy

Added in API level 26
public PersistableBundle deepCopy ()

Make a deep copy of the given bundle. Traverses into inner containers and copies them as well, so they are not shared across bundles. Will traverse in to Bundle, PersistableBundle, ArrayList, and all types of primitive arrays. Other types of objects (such as Parcelable or Serializable) are referenced as-is and not copied in any way.

describeContents

Added in API level 21
public int describeContents ()

Report the nature of this Parcelable's contents

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

getPersistableBundle

Added in API level 21
public PersistableBundle getPersistableBundle (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.

Parameters
key String: a String, or null

Returns
PersistableBundle a Bundle value, or null

putPersistableBundle

Added in API level 21
public void putPersistableBundle (String key, 
                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.

Parameters
key String: a String, or null

value PersistableBundle: a Bundle object, or null

readFromStream

Added in API level 30
public static PersistableBundle readFromStream (InputStream inputStream)

Reads a PersistableBundle from an InputStream.

The stream must be generated by writeToStream(OutputStream).

Parameters
inputStream InputStream: This value cannot be null.

Returns
PersistableBundle This value cannot be null.

Throws
IOException

toString

Added in API level 21
public String toString ()

Returns a string representation of the PersistableBundle that may be suitable for debugging. It won't print the internal map if its content hasn't been unparcelled.

Returns
String a string representation of the object.

writeToParcel

Added in API level 21
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.

Parameters
parcel Parcel: The parcel to copy this bundle to.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

writeToStream

Added in API level 30
public void writeToStream (OutputStream outputStream)

Writes the content of the PersistableBundle to a OutputStream.

The content can be read by a readFromStream(InputStream).

Parameters
outputStream OutputStream: This value cannot be null.

Throws
IOException