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
inline Boolean

Retrieves a Boolean value associated with the specified key.

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 Double

Retrieves a Double value associated with the specified key.

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 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 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 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 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 Int

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

Cmn
android

Extension functions

inline T
<T : Any?> SavedStateReader.write(block: SavedStateWriter.() -> T)

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Cmn

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.

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.

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.

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.

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.

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.

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.

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.

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.

size

inline fun size(): Int

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

Returns
Int

The size of the SavedState.

Extension functions

inline fun <T : Any?> SavedStateReader.write(block: SavedStateWriter.() -> T): T

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Parameters
block: SavedStateWriter.() -> T

A lambda function that performs write operations using the SavedStateWriter.

Returns
T

The result of the lambda function's execution.