SavedStateReader


value public final class SavedStateReader


An inline class that encapsulates an opaque SavedState, and provides an API for reading the platform specific state.

See also
read

Summary

Public methods

final boolean

Checks if the SavedState contains the specified key.

final boolean

Checks if the two specified SavedState are deeply equal to one another.

final int

Returns a hash code based on the "deep contents" of specified SavedState.

final @NonNull String

Returns a string representation of the contents of this SavedState as if it is a List.

final @NonNull IBinder

Retrieves an IBinder value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final IBinder

Retrieves a IBinder value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final boolean

Retrieves a Boolean value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull boolean[]

Retrieves a BooleanArray value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final boolean[]

Retrieves a BooleanArray value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final Boolean

Retrieves a Boolean value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final char

Retrieves a Char value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull char[]

Retrieves a CharSequence value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final char[]

Retrieves a CharArray value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final Character

Retrieves a Char value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull CharSequence

Retrieves a CharSequence value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull CharSequence[]

Retrieves an Array of CharSequence values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final CharSequence[]

Retrieves an Array of CharSequence values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull List<@NonNull CharSequence>

Retrieves a List of CharSequence values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final List<@NonNull CharSequence>

Retrieves a List of CharSequence values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final CharSequence

Retrieves a CharSequence value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final double

Retrieves a Double value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull double[]

Retrieves a DoubleArray value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final double[]

Retrieves a DoubleArray value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final Double

Retrieves a Double value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final float

Retrieves a Float value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull float[]

Retrieves a FloatArray value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final float[]

Retrieves a FloatArray value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final Float

Retrieves a Float value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final int

Retrieves an Int value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull int[]

Retrieves a IntArray value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final int[]

Retrieves a IntArray value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull List<@NonNull Integer>

Retrieves a List of String values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final List<@NonNull Integer>

Retrieves a List of Int values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final Integer

Retrieves an Int value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull T

Retrieves a Serializable value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull T
<T extends Serializable> getJavaSerializable(
    @NonNull String key,
    @NonNull KClass<@NonNull T> serializableClass
)

Retrieves a Serializable value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final T

Retrieves a Serializable value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final T
<T extends Serializable> getJavaSerializableOrNull(
    @NonNull String key,
    @NonNull KClass<@NonNull T> serializableClass
)

Retrieves a Serializable value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final long

Retrieves a Long value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull long[]

Retrieves a LongArray value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final long[]

Retrieves a LongArray value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final Long

Retrieves a Long value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull T
<T extends Parcelable> getParcelable(@NonNull String key)

Retrieves a Parcelable value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull T
<T extends Parcelable> getParcelable(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves a Parcelable value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull T[]

Retrieves an Array of Parcelable values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull T[]
<T extends Parcelable> getParcelableArray(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves an Array of Parcelable values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final T[]

Retrieves an Array of Parcelable values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final T[]
<T extends Parcelable> getParcelableArrayOrNull(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves an Array of Parcelable values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull List<@NonNull T>

Retrieves a List of Parcelable values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull List<@NonNull T>
<T extends Parcelable> getParcelableList(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves a List of Parcelable values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final List<@NonNull T>

Retrieves a List of Parcelable values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final List<@NonNull T>
<T extends Parcelable> getParcelableListOrNull(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves a List of Parcelable values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final T

Retrieves a Parcelable value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final T
<T extends Parcelable> getParcelableOrNull(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves a Parcelable value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull SavedState

Retrieves a SavedState value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull SavedState[]

Retrieves an Array of SavedState values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final SavedState[]

Retrieves an Array of SavedState values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull List<@NonNull SavedState>

Retrieves a List of SavedState values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final List<@NonNull SavedState>

Retrieves a List of SavedState values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final SavedState

Retrieves a SavedState value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull Size

Retrieves a Size value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull SizeF

Retrieves a SizeF value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final SizeF

Retrieves a SizeF value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final Size

Retrieves a Size value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull SparseArray<@NonNull T>

Retrieves a SparseArray of Parcelable values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull SparseArray<@NonNull T>
<T extends Parcelable> getSparseParcelableArray(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves a SparseArray of Parcelable values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final SparseArray<@NonNull T>

Retrieves a Array of Parcelable values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final SparseArray<@NonNull T>
<T extends Parcelable> getSparseParcelableArrayOrNull(
    @NonNull String key,
    @NonNull KClass<@NonNull T> parcelableClass
)

Retrieves a Array of Parcelable values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull String

Retrieves a String value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final @NonNull String[]

Retrieves an Array of String values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final String[]

Retrieves an Array of String values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final @NonNull List<@NonNull String>

Retrieves a List of String values associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

final List<@NonNull String>

Retrieves a List of String values associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final String

Retrieves a String value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

final boolean

Checks if the SavedState is empty (contains no key-value pairs).

final boolean

Checks if the SavedState contains a null reference for the specified key.

final int

Returns the number of key-value pairs in the SavedState.

final @NonNull Map<@NonNull StringObject>

Returns a new Map containing all key-value pairs from the SavedState.

Public methods

contains

Added in 1.3.0-rc01
public final boolean contains(@NonNull String key)

Checks if the SavedState contains the specified key.

Parameters
@NonNull String key

The key to check for.

Returns
boolean

true if the SavedState contains the key, false otherwise.

contentDeepEquals

public final boolean contentDeepEquals(@NonNull SavedState other)

Checks if the two specified SavedState are deeply equal to one another.

Two SavedState are considered deeply equal if they have the same size, and elements at corresponding keys are deeply equal. That is, if two corresponding elements are nested SavedState, they are also compared deeply.

If any of SavedState contains itself on any nesting level the behavior is undefined.

Parameters
@NonNull SavedState other

the object to compare deeply with this.

Returns
boolean

true if the two are deeply equal, false otherwise.

contentDeepHashCode

Added in 1.3.0-rc01
public final int contentDeepHashCode()

Returns a hash code based on the "deep contents" of specified SavedState. If the SavedState contains other SavedState as elements, the hash code is based on their contents and so on.

The computation of the hash code returned is as if the SavedState is a List. Nested SavedState are treated as lists too.

If any of SavedState contains itself on any nesting level the behavior is undefined.

Returns
int

a deep-content-based hash code for SavedState.

contentDeepToString

Added in 1.3.0-rc01
public final @NonNull String contentDeepToString()

Returns a string representation of the contents of this SavedState as if it is a List. Nested SavedState are treated as lists too.

If any of SavedState contains itself on any nesting level that reference is rendered as "[...]" to prevent recursion.

getBinder

Added in 1.3.0-rc01
public final @NonNull IBinder getBinder(@NonNull String key)

Retrieves an IBinder value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

More specifically, a SavedState is considered to contain a valid value for a key if the key exists, the associated value is not null, and it is of the expected type.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull IBinder

The value associated with the key.

Throws
kotlin.IllegalArgumentException

If the key is not found.

kotlin.IllegalArgumentException

If associated value is null.

kotlin.IllegalArgumentException

if associated value has wrong type.

getBinderOrNull

Added in 1.3.0-rc01
public final IBinder getBinderOrNull(@NonNull String key)

Retrieves a IBinder value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

More specifically, a SavedState is considered to contain a valid value for a key if the key exists, the associated value is not null, and it is of the expected type.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
IBinder

The value associated with the key, or null if no valid value is found.

getBoolean

Added in 1.3.0-rc01
public final boolean getBoolean(@NonNull String key)

Retrieves a Boolean value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

More specifically, a SavedState is considered to contain a valid value for a key if the key exists, the associated value is not null, and it is of the expected type.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
boolean

The value associated with the key.

Throws
kotlin.IllegalArgumentException

If the key is not found.

kotlin.IllegalArgumentException

If associated value is null.

kotlin.IllegalArgumentException

if associated value has wrong type.

getBooleanArray

Added in 1.3.0-rc01
public final @NonNull boolean[] getBooleanArray(@NonNull String key)

Retrieves a BooleanArray value associated with the specified key, or throws an IllegalArgumentException if this SavedState does not contain a valid value for the key.

More specifically, a SavedState is considered to contain a valid value for a key if the key exists, the associated value is not null, and it is of the expected type.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull boolean[]

The value associated with the key.

Throws
kotlin.IllegalArgumentException

If the key is not found.

kotlin.IllegalArgumentException

If associated value is null.

kotlin.IllegalArgumentException

if associated value has wrong type.

getBooleanArrayOrNull

Added in 1.3.0-rc01
public final boolean[] getBooleanArrayOrNull(@NonNull String key)

Retrieves a BooleanArray value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

More specifically, a SavedState is considered to contain a valid value for a key if the key exists, the associated value is not null, and it is of the expected type.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
boolean[]

The value associated with the key, or null if no valid value is found.

getBooleanOrNull

Added in 1.3.0-rc01
public final Boolean getBooleanOrNull(@NonNull String key)

Retrieves a Boolean value associated with the specified key, or null if this SavedState does not contain a valid value for the key.

More specifically, a SavedState is considered to contain a valid value for a key if the key exists, the associated value is not null, and it is of the expected type.

Note: This method returns a nullable primitive, causing auto-boxing on JVM targets.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
Boolean

The value associated with the key, or null if no valid value is found.

getChar

Added in 1.3.0-rc01
public final char getChar(@NonNull String key)

Retrieves a Char value associated with the specified key, or throws an IllegalArgumentException if this