SavedStateReader



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

See also
read

Summary

Public functions

inline operator Boolean

Checks if the SavedState contains the specified key.

Cmn
android
Boolean

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

Cmn
android
Int

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

Cmn
android
inline Boolean

Retrieves a Boolean value associated with the specified key.

Cmn
android
inline BooleanArray

Retrieves a BooleanArray value associated with the specified key.

Cmn
android
inline BooleanArray
getBooleanArrayOrElse(key: String, defaultValue: () -> BooleanArray)

Retrieves a BooleanArray value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Boolean
getBooleanOrElse(key: String, defaultValue: () -> Boolean)

Retrieves a Boolean value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Char

Retrieves a Char value associated with the specified key.

Cmn
android
inline CharArray

Retrieves a CharArray value associated with the specified key.

Cmn
android
inline CharArray
getCharArrayOrElse(key: String, defaultValue: () -> CharArray)

Retrieves a CharArray value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Char
getCharOrElse(key: String, defaultValue: () -> Char)

Retrieves a Char value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Double

Retrieves a Double value associated with the specified key.

Cmn
android
inline DoubleArray

Retrieves a DoubleArray value associated with the specified key.

Cmn
android
inline DoubleArray
getDoubleArrayOrElse(key: String, defaultValue: () -> DoubleArray)

Retrieves a DoubleArray value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Double
getDoubleOrElse(key: String, defaultValue: () -> Double)

Retrieves a Double value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Float

Retrieves a Float value associated with the specified key.

Cmn
android
inline FloatArray

Retrieves a FloatArray value associated with the specified key.

Cmn
android
inline FloatArray
getFloatArrayOrElse(key: String, defaultValue: () -> FloatArray)

Retrieves a FloatArray value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Float
getFloatOrElse(key: String, defaultValue: () -> Float)

Retrieves a Float value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Int
getInt(key: String)

Retrieves an Int value associated with the specified key.

Cmn
android
inline IntArray

Retrieves a IntArray value associated with the specified key.

Cmn
android
inline IntArray
getIntArrayOrElse(key: String, defaultValue: () -> IntArray)

Retrieves a IntArray value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline List<Int>

Retrieves a List of elements of Int associated with the specified key.

Cmn
android
inline List<Int>
getIntListOrElse(key: String, defaultValue: () -> List<Int>)

Retrieves a List of elements of Int associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Int
getIntOrElse(key: String, defaultValue: () -> Int)

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Long

Retrieves an Long value associated with the specified key.

Cmn
android
inline LongArray

Retrieves a LongArray value associated with the specified key.

Cmn
android
inline LongArray
getLongArrayOrElse(key: String, defaultValue: () -> LongArray)

Retrieves a LongArray value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Long
getLongOrElse(key: String, defaultValue: () -> Long)

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline T

Retrieves a Parcelable object associated with the specified key.

android
inline List<T>

Retrieves a List of elements of Parcelable associated with the specified key.

android
inline List<T>
<T : Parcelable> getParcelableListOrElse(
    key: String,
    defaultValue: () -> List<T>
)

Retrieves a List of elements of Parcelable associated with the specified key, or a default value if the key doesn't exist.

android
inline T
<T : Parcelable> getParcelableOrElse(key: String, defaultValue: () -> T)

Retrieves a Parcelable object associated with the specified key, or a default value if the key doesn't exist.

android
inline SavedState

Retrieves a SavedState object associated with the specified key.

Cmn
android
inline SavedState
getSavedStateOrElse(key: String, defaultValue: () -> SavedState)

Retrieves a SavedState object associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline String

Retrieves a String value associated with the specified key.

Cmn
android
inline Array<String>

Retrieves a Array of String value associated with the specified key.

Cmn
android
inline Array<String>
getStringArrayOrElse(key: String, defaultValue: () -> Array<String>)

Retrieves a Array of String value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline List<String>

Retrieves a List of elements of String associated with the specified key.

Cmn
android
inline List<String>
getStringListOrElse(key: String, defaultValue: () -> List<String>)

Retrieves a List of elements of String associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline String
getStringOrElse(key: String, defaultValue: () -> String)

Retrieves a String value associated with the specified key, or a default value if the key doesn't exist.

Cmn
android
inline Boolean

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

Cmn
android
inline Boolean
isNull(key: String)

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

Cmn
android
inline Int

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

Cmn
android
Map<StringAny?>

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

Cmn
android

Public functions

contains

inline operator fun contains(key: String): Boolean

Checks if the SavedState contains the specified key.

Parameters
key: String

The key to check for.

Returns
Boolean

true if the SavedState contains the key, false otherwise.

contentDeepEquals

fun contentDeepEquals(other: SavedState): Boolean

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
other: SavedState

the object to compare deeply with this.

Returns
Boolean

true if the two are deeply equal, false otherwise.

contentDeepHashCode

fun contentDeepHashCode(): Int

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.

getBoolean

inline fun getBoolean(key: String): Boolean

Retrieves a Boolean value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
Boolean

The Boolean value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getBooleanArray

inline fun getBooleanArray(key: String): BooleanArray

Retrieves a BooleanArray value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
BooleanArray

The BooleanArray value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getBooleanArrayOrElse

inline fun getBooleanArrayOrElse(key: String, defaultValue: () -> BooleanArray): BooleanArray

Retrieves a BooleanArray value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> BooleanArray

A function providing the default value if the key is not found.

Returns
BooleanArray

The BooleanArray value associated with the key, or the default value if the key is not found.

getBooleanOrElse

inline fun getBooleanOrElse(key: String, defaultValue: () -> Boolean): Boolean

Retrieves a Boolean value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> Boolean

A function providing the default value if the key is not found.

Returns
Boolean

The Boolean value associated with the key, or the default value if the key is not found.

getChar

inline fun getChar(key: String): Char

Retrieves a Char value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
Char

The Char value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getCharArray

inline fun getCharArray(key: String): CharArray

Retrieves a CharArray value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
CharArray

The CharArray value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getCharArrayOrElse

inline fun getCharArrayOrElse(key: String, defaultValue: () -> CharArray): CharArray

Retrieves a CharArray value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> CharArray

A function providing the default value if the key is not found.

Returns
CharArray

The CharArray value associated with the key, or the default value if the key is not found.

getCharOrElse

inline fun getCharOrElse(key: String, defaultValue: () -> Char): Char

Retrieves a Char value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> Char

A function providing the default value if the key is not found.

Returns
Char

The Char value associated with the key, or the default value if the key is not found.

getDouble

inline fun getDouble(key: String): Double

Retrieves a Double value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
Double

The Double value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getDoubleArray

inline fun getDoubleArray(key: String): DoubleArray

Retrieves a DoubleArray value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
DoubleArray

The DoubleArray value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getDoubleArrayOrElse

inline fun getDoubleArrayOrElse(key: String, defaultValue: () -> DoubleArray): DoubleArray

Retrieves a DoubleArray value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> DoubleArray

A function providing the default value if the key is not found.

Returns
DoubleArray

The DoubleArray value associated with the key, or the default value if the key is not found.

getDoubleOrElse

inline fun getDoubleOrElse(key: String, defaultValue: () -> Double): Double

Retrieves a Double value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> Double

A function providing the default value if the key is not found.

Returns
Double

The Double value associated with the key, or the default value if the key is not found.

getFloat

inline fun getFloat(key: String): Float

Retrieves a Float value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
Float

The Float value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getFloatArray

inline fun getFloatArray(key: String): FloatArray

Retrieves a FloatArray value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
FloatArray

The FloatArray value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getFloatArrayOrElse

inline fun getFloatArrayOrElse(key: String, defaultValue: () -> FloatArray): FloatArray

Retrieves a FloatArray value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> FloatArray

A function providing the default value if the key is not found.

Returns
FloatArray

The FloatArray value associated with the key, or the default value if the key is not found.

getFloatOrElse

inline fun getFloatOrElse(key: String, defaultValue: () -> Float): Float

Retrieves a Float value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> Float

A function providing the default value if the key is not found.

Returns
Float

The Float value associated with the key, or the default value if the key is not found.

getInt

inline fun getInt(key: String): Int

Retrieves an Int value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
Int

The Int value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getIntArray

inline fun getIntArray(key: String): IntArray

Retrieves a IntArray value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
IntArray

The IntArray value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getIntArrayOrElse

inline fun getIntArrayOrElse(key: String, defaultValue: () -> IntArray): IntArray

Retrieves a IntArray value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> IntArray

A function providing the default value if the key is not found.

Returns
IntArray

The IntArray value associated with the key, or the default value if the key is not found.

getIntList

inline fun getIntList(key: String): List<Int>

Retrieves a List of elements of Int associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
List<Int>

The List of elements of Int associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getIntListOrElse

inline fun getIntListOrElse(key: String, defaultValue: () -> List<Int>): List<Int>

Retrieves a List of elements of Int associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> List<Int>

A function providing the default value if the key is not found or the retrieved value is not a list of Int.

Returns
List<Int>

The list of elements of Int associated with the key, or the default value if the key is not found.

getIntOrElse

inline fun getIntOrElse(key: String, defaultValue: () -> Int): Int

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> Int

A function providing the default value if the key is not found.

Returns
Int

The Int value associated with the key, or the default value if the key is not found.

getLong

inline fun getLong(key: String): Long

Retrieves an Long value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
Long

The Long value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getLongArray

inline fun getLongArray(key: String): LongArray

Retrieves a LongArray value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
LongArray

The LongArray value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getLongArrayOrElse

inline fun getLongArrayOrElse(key: String, defaultValue: () -> LongArray): LongArray

Retrieves a LongArray value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> LongArray

A function providing the default value if the key is not found.

Returns
LongArray

The LongArray value associated with the key, or the default value if the key is not found.

getLongOrElse

inline fun getLongOrElse(key: String, defaultValue: () -> Long): Long

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> Long

A function providing the default value if the key is not found.

Returns
Long

The Int value associated with the key, or the default value if the key is not found.

getParcelable

inline fun <T : Parcelable> getParcelable(key: String): T

Retrieves a Parcelable object associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
T

The Parcelable object associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getParcelableList

inline fun <T : Parcelable> getParcelableList(key: String): List<T>

Retrieves a List of elements of Parcelable associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
List<T>

The List of elements of Parcelable associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getParcelableListOrElse

inline fun <T : Parcelable> getParcelableListOrElse(
    key: String,
    defaultValue: () -> List<T>
): List<T>

Retrieves a List of elements of Parcelable associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> List<T>

A function providing the default value if the key is not found or the retrieved value is not a list of Parcelable.

Returns
List<T>

The list of elements of Parcelable associated with the key, or the default value if the key is not found.

getParcelableOrElse

inline fun <T : Parcelable> getParcelableOrElse(key: String, defaultValue: () -> T): T

Retrieves a Parcelable object associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> T

A function providing the default Parcelable if the key is not found.

Returns
T

The Parcelable object associated with the key, or the default value if the key is not found.

getSavedState

inline fun getSavedState(key: String): SavedState

Retrieves a SavedState object associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
SavedState

The SavedState object associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getSavedStateOrElse

inline fun getSavedStateOrElse(key: String, defaultValue: () -> SavedState): SavedState

Retrieves a SavedState object associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> SavedState

A function providing the default SavedState if the key is not found.

Returns
SavedState

The SavedState object associated with the key, or the default value if the key is not found.

getString

inline fun getString(key: String): String

Retrieves a String value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
String

The String value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getStringArray

inline fun getStringArray(key: String): Array<String>

Retrieves a Array of String value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
Array<String>

The Array of String value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getStringArrayOrElse

inline fun getStringArrayOrElse(key: String, defaultValue: () -> Array<String>): Array<String>

Retrieves a Array of String value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> Array<String>

A function providing the default value if the key is not found.

Returns
Array<String>

The Array of String value associated with the key, or the default value if the key is not found.

getStringList

inline fun getStringList(key: String): List<String>

Retrieves a List of elements of String associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

Returns
List<String>

The List of elements of String associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getStringListOrElse

inline fun getStringListOrElse(key: String, defaultValue: () -> List<String>): List<String>

Retrieves a List of elements of String associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> List<String>

A function providing the default value if the key is not found or the retrieved value is not a list of String.

Returns
List<String>

The list of elements of String associated with the key, or the default value if the key is not found.

getStringOrElse

inline fun getStringOrElse(key: String, defaultValue: () -> String): String

Retrieves a String value associated with the specified key, or a default value if the key doesn't exist.

Parameters
key: String

The key to retrieve the value for.

defaultValue: () -> String

A function providing the default value if the key is not found.

Returns
String

The String value associated with the key, or the default value if the key is not found.

isEmpty

inline fun isEmpty(): Boolean

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

Returns
Boolean

true if the SavedState is empty, false otherwise.

isNull

inline fun isNull(key: String): Boolean

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

Parameters
key: String

The key to check for.

Returns
Boolean

true if the SavedState contains a null reference for the key, false otherwise.

size

inline fun size(): Int

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

Returns
Int

The size of the SavedState.

toMap

fun toMap(): Map<StringAny?>

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

The returned Map does not preserve the entry iteration order of the SavedState.

IMPORTANT: All values will be copied by reference, and values within the SavedState that are also a SavedState will NOT be converted to a Map.

Returns
Map<StringAny?>

A Map containing all key-value pairs from the SavedState.