Savedstate
| Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |
|---|---|---|---|---|
| October 22, 2025 | 1.3.3 | 1.4.0-rc01 | - | - |
Declaring dependencies
To add a dependency on SavedState, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.
Add the dependencies for the artifacts you need in the build.gradle file for
your app or module:
Groovy
dependencies { // Java language implementation implementation "androidx.savedstate:savedstate:1.3.3" // Kotlin implementation "androidx.savedstate:savedstate-ktx:1.3.3" }
Kotlin
dependencies { // Java language implementation implementation("androidx.savedstate:savedstate:1.3.3") // Kotlin implementation("androidx.savedstate:savedstate-ktx:1.3.3") }
For more information about dependencies, see Add build dependencies.
Feedback
Your feedback helps make Jetpack better. Let us know if you discover new issues or have ideas for improving this library. Please take a look at the existing issues in this library before you create a new one. You can add your vote to an existing issue by clicking the star button.
See the Issue Tracker documentation for more information.
Version 1.4
Version 1.4.0-rc01
October 22, 2025
androidx.savedstate:savedstate-*:1.4.0-rc01 is released with no changes since 1.4.0-beta01. Version 1.4.0-rc01 contains these commits.
Version 1.4.0-beta01
October 08, 2025
androidx.savedstate:savedstate-*:1.4.0-beta01 is released with no notable changes since the last alpha. Version 1.4.0-beta01 contains these commits.
Version 1.4.0-alpha03
August 27, 2025
androidx.savedstate:savedstate-*:1.4.0-alpha03 is released. Version 1.4.0-alpha03 contains these commits.
API Changes
- Add support for nullable types in
encodeToSavedStateanddecodeFromSavedState. (I79062, b/439527454) - Update Compose to 1.9.0. (I2b9de)
Version 1.4.0-alpha02
August 13, 2025
androidx.savedstate:savedstate-*:1.4.0-alpha02 is released. Version 1.4.0-alpha02 contains these commits.
Version 1.4.0-alpha01
July 30, 2025
androidx.savedstate:savedstate-*:1.4.0-alpha01 is released. Version 1.4.0-alpha01 contains these commits.
API Changes
- Add native support for nullable types in
SavedStateRegistryOwner.saved, simplifying saving and restoring nullable properties. (Ia632, b/421325690)
Version 1.3
Version 1.3.3
September 17, 2025
androidx.savedstate:savedstate-*:1.3.3 is released. Version 1.3.3 contains these commits.
Bug Fixes
- Fixed an error with the Compose Compiler plugin not being applied that caused
SavedStateKMP artifacts to be broken. (Id2290, b/443965665)
Version 1.3.2
August 27, 2025
androidx.savedstate:savedstate-*:1.3.2 is released. Version 1.3.2 contains these commits.
New Features
- Add new Kotlin Multiplatform (KMP) targets to SavedState
*-composeartifact. Lifecycle now supports the following platforms in total: JVM (Android and Desktop), Native (Linux, iOS, watchOS, macOS, MinGW), and Web (JavaScript, WasmJS). (/Idcf26)
Version 1.3.1
July 16, 2025
androidx.savedstate:savedstate-*:1.3.1 is released. Version 1.3.1 contains these commits.
Bug Fixes
- Add all KMP targets supported by annotations to
SavedStateartifacts. - Added new Kotlin Multiplatform (KMP) targets to
SavedStateartifacts.SavedStatenow supports the following platforms in total: JVM (Android and Desktop), Native (Linux, iOS, watchOS, macOS, MinGW), and Web (JavaScript, WasmJS). Note that no new KMP targets have been added to the*-composeartifacts, as this depends on the stable release of Compose 1.9. (I062f4).
Version 1.3.0
May 7, 2025
androidx.savedstate:savedstate-*:1.3.0 is released. Version 1.3.0 contains these commits.
Important changes since 1.2.0
LocalSavedStateRegistryOwnerhas been moved from Compose UI to the newsavedstate-composemodule so that its Compose-based helper APIs can be used outside of Compose UI. This should always be used when using Compose UI1.9.0-alpha02and higher, but is backward compatible such that it can be used with all versions of Compose.- The
savedstate-ktxkotlin extensions have now been moved to the base savedstate module. SavedStateRegistryOwnerinstances retrieved viafindViewTreeSavedStateRegistryOwnercan now be resolved through disjoint parents of a view, such as aViewOverlay. See the release notes of core or the documentation inViewTree.setViewTreeDisjointParentfor more information on disjoint view parents.
Kotlin Multiplatform
- The
SavedStatemodule is now KMP compatible. Supported platforms now include Android, iOS, Linux, Mac, and JVM desktop environments. Introduce
SavedStateopaque type as an abstraction to provide a consistent way to save and restore application state in KMP. It includes aSavedStateReaderandSavedStateWriterfor modifying the state to be saved. On Android,SavedStateis a type alias forBundle, ensuring binary compatibility and facilitating the migration of existing APIs to a common source set. On other platforms,SavedStateis aMap<String, Any>instance.// Create a new SavedState object using the savedState DSL: val savedState = savedState { putInt("currentPage", 1) putString("filter", "favorites") } // Read from a SavedState object val currentPage = savedState.read { getInt("currentPage") } // Edit an existing SavedState object savedState.write { remove("currentPage") }
KotlinX Serialization Support
SavedStatenow includes KotlinX Serialization support. You can convert a class annotated with@Serializableto aSavedStateusing the methodsencodeToSavedStateanddecodeFromSavedState. The returnedSavedStateis a regularBundleon Android and can be used by any API that accepts aBundle.@Serializable data class Person(val firstName: String, val lastName: String) fun main() { val person = Person("John", "Doe") val encoded: SavedState = encodeToSavedState(person) val decoded: Person = decodeFromSavedState(encoded) }While most types (such as primitive types) are directly supported without any configuration needed, additional serializers that can be used with
@Serializable(with = ___:class)can be found in theandroidx.savedstate.serialization.serializerspackage in thesavedstatemodule and theandroidx.savedstate.compose.serialization.serializerspackage in thesavedstate-composemodule.We also have included
saved, a lazy property delegate, to make it easy to store@Serializableclasses in aSavedStateRegistryOwner(e.g.,ComponentActivity,Fragment, etc.) and have those classes automatically be restored across process death and recreation. Please note thesaveddelegate is lazy and will not call theinitlambda or save anything into theSavedStateRegistryuntil it is accessed.@Serializable data class Person(val firstName: String, val lastName: String) class MyActivity : ComponentActivity() { var person by saved { Person("John", "Doe") } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) this.person = Person("Jane", "Doe") } }There is a similar
savedproperty delegate forSavedStateHandleadded in Lifecycle2.9.0.
Version 1.3.0-rc01
April 23, 2025
androidx.savedstate:savedstate-*:1.3.0-rc01 is released. Version 1.3.0-rc01 contains these commits.
Version 1.3.0-beta01
April 9, 2025
androidx.savedstate:savedstate-*:1.3.0-beta01 is released. Version 1.3.0-beta01 contains these commits.
Dependency Updates
- This library now targets Kotlin 2.0 language level and requires KGP 2.0.0 or newer. (Idb6b5)
Version 1.3.0-alpha11
March 26, 2025
androidx.savedstate:savedstate-*:1.3.0-alpha11 is released with no notable public changes. Version 1.3.0-alpha11 contains these commits.
Version 1.3.0-alpha10
March 12, 2025
androidx.savedstate:savedstate-*:1.3.0-alpha10 is released. Version 1.3.0-alpha10 contains these commits.
New Features
- Add non-reified method variants for
getcollections inSavedStateReader. (I0b641, b/399820614) - Add
encodeDefaultstoSavedStateConfiguration, allowing customizing whether properties with default values should be encoded. (I893cc, b/395104517) - Add
SnapshotStateMapSerializerto supportmutableStateMapOf. (Ie6f19, b/378895074) - Add
SnapshotStateListSerializerto supportmutableStateListOf. (I4d888, b/378895074) - Add
getOrNullalternative methods forSavedStateReader.getvariants. These methods will auto-box primitive values. (I6228c, b/399820614)
API Changes
- Remove
getOrElsefromSavedStateReaderin favor ofgetOrNull() ?: else(). (I87317, b/399820614) - Remove
inlinemodifier fromSavedStateReaderandSavedStateWritermethods. (If2a02, b/399820614) - Remove built-in Android-specific List and Array serializers out of public API (Ida293)
- Replace
SparseParcelableArraySerializerwithSparseArraySerializer(I91de8) - Make all
SavedStateReader.getbehave consistently by throwing when value type doesn't match return type (I78c4a, b/399317598) - Rename
SavedState*DelegatestoSavedState*Delegate. (I8589b, b/399629301) - Rename
SavedStateConfigtoSavedStateConfiguration. (I043a5, b/399629301)
Version 1.3.0-alpha09
February 26, 2025
androidx.savedstate:savedstate-*:1.3.0-alpha09 is released. Version 1.3.0-alpha09 contains these commits.
New Features
- Add fallback for built-in types, ensuring that all types supported by
Bundlecan be used withencodeAsSavedState/decodeFromSavedStateby default or, for properties in@Serializableclasses, via the@Contextualannotation. (Ic01d2) - Include support for
classDiscriminatorandclassDiscriminatorModeonSavedStateConfig. (I69b66, b/395104517)
API Changes
- Add
SavedStateConfigparameter tosaved()delegates (I39b3a) - Makes built-in serializers singleton objects (Ifeee4)
SavedStateConfigproperties are now public, enabling other modules to use these configurations. (Ie5f49, b/378897438)- Support
@Serializer(with = ...)forMutableStateFlowSerializerandMutableStateSerializer(I90953) - Add
contentDeepToStringtoSavedStateReader(I14d10)
Version 1.3.0-alpha08
February 12, 2025
androidx.savedstate:savedstate-*:1.3.0-alpha08 is released. Version 1.3.0-alpha08 contains these commits.
New Features
- Move
MutableStateSerializertosavedstate-composefromlifecycle-viewmodel-compose, allowing you to use the SavedState Serialization APIs with Compose’sMutableState. (I4f690, b/378895074)
API Changes
- Add a factory function to create
SavedStatefrom an existingSavedState. (I39f9a) - Adds support for
Array<SavedState>andList<SavedState>inandroidx.savedstate. (Idd8a5) - Add
SavedStateConfigoptional parameter to SavedState encoding/decoding (I6c4c0)
Version 1.3.0-alpha07
January 29, 2025
androidx.savedstate:savedstate-*:1.3.0-alpha07 is released. Version 1.3.0-alpha07 contains these commits.
New Features
- Add
MutableStateFlowSerializerfor serializingkotlinx.coroutines.flow.MutableStateFlow. (I6a892, b/378895070)
API Changes
- Replace overloaded
SavedStateRegistryOwner.saved()delegate functions with default parameters (Icd1c1) - Make
JavaSerializableSerializerandParcelableSerializerabstract (I268f6) - Remove generic
T : CharSequencefromCharSequenceSerializer(Ib40bd)
Version 1.3.0-alpha06
December 11, 2024
androidx.savedstate:savedstate-*:1.3.0-alpha06 is released. Version 1.3.0-alpha06 contains these commits.
New Features
SavedStateKMP now supports:IBinder,Size,SizeF,Array<Parcelable>,SparseArray<Parcelable>and Serializable (Android). (I1ba94, b/334076622)- Add
KSerializerinstances that can be used to encode/decode Java and Android types supported by Bundle by marking the relevant field in your class with@Serializable(with = ParcelableSerializer::class). (I8c10f, I28caf, b/376026712) SavedStateRegistryOwnerinstances retrieved viafindViewTreeSavedStateRegistryOwnercan now be resolved through disjoint parents of a view, such as aViewOverlay. See the release notes of core or the documentation inViewTree.setViewTreeDisjointParentfor more information on disjoint view parents. (Iccb33)
API Changes
- Make the namings and package organization more consistent with
SavedStateRegistryOwnerDelegate(I8c135, b/376026744)
Version 1.3.0-alpha05
November 13, 2024
androidx.savedstate:savedstate-*:1.3.0-alpha05 is released. Version 1.3.0-alpha05 contains these commits.
KotlinX Serialization Support
SavedStatenow includes KotlinX Serialization support. You can convert a class annotated with@Serializableto aSavedStateusing the methodsencodeToSavedStateanddecodeFromSavedState. The returnedSavedStateis a regularBundleon Android and can be used by any API that accepts aBundle. (I6f59f, b/374102924)@Serializable data class Person(val firstName: String, val lastName: String) fun main() { val person = Person("John", "Doe") val encoded: SavedState = encodeToSavedState(person) val decoded: Person = decodeFromSavedState(encoded) }We also have included
saved, a lazy property delegate, to make it easy to store@Serializableclasses in aSavedStateRegistryOwner(e.g.,ComponentActivity,Fragment, etc.) and have those classes automatically be restored across process death and recreation. Please note thesaveddelegate is lazy and will not call theinitlambda or save anything into theSavedStateRegistryuntil it is accessed. (I66739, b/376027806)@Serializable data class Person(val firstName: String, val lastName: String) class MyActivity : ComponentActivity() { var person by saved { Person("John", "Doe") } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) this.person = Person("Jane", "Doe") } }There is a similar
savedproperty delegate forSavedStateHandleadded in Lifecycle2.9.0-alpha07.
API Changes
- Add
toMaptoSavedState, allowing anySavedStateto be converted to a regularMap(shallow copy). (I487b9, b/334076622) SavedStateKMP now supports arrays. (Ic0552, b/334076622)
Version 1.3.0-alpha04
October 30, 2024
androidx.savedstate:savedstate-*:1.3.0-alpha04 is released. Version 1.3.0-alpha04 contains these commits.
API Changes
- SavedState KMP now supports Char. (I9ac2f, b/334076622)
- Add
putNullandisNullto SavedState KMP. (Iea71d, b/334076622) - Add additional
savedStatefactory parameters supporting an initialMap<String, Any>(I9b37d, b/334076622) - SavedState KMP now supports
contentDeepEqualscomparison. (Ia515c, b/334076622) - SavedState KMP now supports Long. (I4c180, b/334076622)
Version 1.3.0-alpha03
October 16, 2024
androidx.savedstate:savedstate-*:1.3.0-alpha03 is released with no notable changes. Version 1.3.0-alpha03 contains these commits.
Version 1.3.0-alpha02
October 2, 2024
androidx.savedstate:savedstate-*:1.3.0-alpha02 is released. Version 1.3.0-alpha02 contains these commits.
Kotlin Multiplatform
- The
SavedStatemodule is now KMP compatible. Supported platforms now include Android, iOS, Linux, Mac, and JVM desktop environments. (I26305, b/334076622)
New Features
- Introduce
SavedStateopaque type as an abstraction to provide a consistent way to save and restore application state in KMP. It includes aSavedStateReaderandSavedStateWriterfor modifying the state to be saved. On Android,SavedStateis a type alias forBundle, ensuring binary compatibility and facilitating the migration of existing APIs to a common source set. On other platforms,SavedStateis aMap<String, Any>instance. (I18575, b/334076622)
// Create a new SavedState object using the savedState DSL:
val savedState = savedState {
putInt("currentPage", 1)
putString("filter", "favorites")
}
// Read from a SavedState object
val currentPage = savedState.read { getInt("currentPage") }
// Edit an existing SavedState object
savedState.write {
remove("currentPage")
}
API Changes
SavedStateRegistryandSavedStateRegistryControllerare now KMP compatible. (Id7bb8, b/334076622)SavedState,SavedStateWriterandSavedStateReaderare now KMP compatible. (I26305, b/334076622)
Version 1.3.0-alpha01
August 7, 2024
androidx.savedstate:savedstate:1.3.0-alpha01 and androidx.savedstate:savedstate-ktx:1.3.0-alpha01 are released. Version 1.3.0-alpha01 contains these commits.
API Changes
- The
savedstate-ktxkotlin extensions have now been moved to the base savedstate module. (I1cc18, b/274803094)
Note
- Update
compileSdkto 35 (5dc41be)
Version 1.2.1
Version 1.2.1
March 22, 2023
androidx.savedstate:savedstate:1.2.1 and androidx.savedstate:savedstate-ktx:1.2.1 are released. Version 1.2.1 contains these commits.
Dependency Updates
SavedStatenow depends on Lifecycle2.6.1. (c1f621)
Version 1.2.0
Version 1.2.0
June 29, 2022
androidx.savedstate:savedstate:1.2.0 and androidx.savedstate:savedstate-ktx:1.2.0 are released. Version 1.2.0 contains these commits.
Important changes since 1.1.0
SavedStateRegistryControllernow allows early attachment of theSavedStateRegistryviaperformAttach().- You can now retrieve a previously registered
SavedStateProviderfrom aSavedStateRegistryviagetSavedStateProvider(). - The
SavedStatelibrary has been rewritten in Kotlin.- For
SavedStateRegistryOwner, this is a source incompatible change for those classes written in Kotlin - you must now override thesavedStateRegistryproperty rather than implement the previousgetSavedStateRegistry()function. - For
ViewTreeSavedStateRegistryOwner, this is a source incompatible change for those classes written in Kotlin - you must now directly import and use the Kotlin extension methods onViewofandroidx.savedstate.setViewTreeSavedStateRegistryOwnerandandroidx.savedstate.findViewTreeSavedStateRegistryOwnerto set and find a previously set owner. This replaces thesavedstate-ktxAPI offindViewTreeSavedStateRegistryOwner.
- For
Behavior Changes
SavedStateRegistryno longer saves an empty Bundle if there is no state to save.
Version 1.2.0-rc01
May 11, 2022
androidx.savedstate:savedstate:1.2.0-rc01 and androidx.savedstate:savedstate-ktx:1.2.0-rc01 are released. Version 1.2.0-rc01 contains these commits.
Documentation Changes
- The
SavedStateRegistryOwnerKdocs have been updated to clarify the responsibilities and contract that the owner has on how it should implement the interface or when they should call the methods onSavedStateRegistryController. (Iefc95, b/228887344)
Version 1.2.0-beta01
April 20, 2022
androidx.savedstate:savedstate:1.2.0-beta01 and androidx.savedstate:savedstate-ktx:1.2.0-beta01 are released. Version 1.2.0-beta01 contains these commits.
API Changes
- The
SavedStateRegistryandViewTreeSavedStateRegistryOwnerclasses have been rewritten in Kotlin. ForViewTreeSavedStateRegistryOwner, this is a source incompatible change for those classes written in Kotlin - you must now directly import and use the Kotlin extension methods onViewofandroidx.savedstate.setViewTreeSavedStateRegistryOwnerandandroidx.savedstate.findViewTreeSavedStateRegistryOwnerto set and find a previously set owner. This replaces thesavedstate-ktxAPI offindViewTreeSavedStateRegistryOwner. This is binary compatible and remains source compatible for implementations written in the Java programming language. (b/220191285)
Version 1.2.0-alpha02
April 6, 2022
androidx.savedstate:savedstate:1.2.0-alpha02 and androidx.savedstate:savedstate-ktx:1.2.0-alpha02 are released. Version 1.2.0-alpha02 contains these commits.
New Features
- You can now retrieve a previously registered
SavedStateProviderfrom aSavedStateRegistryviagetSavedStateProvider(). (I7ea47, b/215406268)
API Changes
- The
SavedStateRegistryOwner,SavedStateRegistryController, andRecreatorclasses have been rewritten in Kotlin. ForSavedStateRegistryOwner, this is a source incompatible change for those classes written in Kotlin - you must now override thesavedStateRegistryproperty rather than implement the previousgetSavedStateRegistry()function. This is binary compatible and source compatible for implementations written in the Java programming language. (b/220191285)
Version 1.2.0-alpha01
January 26, 2022
androidx.savedstate:savedstate:1.2.0-alpha01 and androidx.savedstate:savedstate-ktx:1.2.0-alpha01 are released. Version 1.2.0-alpha01 contains these commits.
New Features
SavedStateRegistryControllernow allows early attachment of theSavedStateRegistryviaperformAttach(). (Ice4bf)
Behavior Changes
SavedStateRegistryno longer saves an empty Bundle if there is no state to save. (aosp/1896865, b/203457956)
Version 1.1.0
Version 1.1.0
February 10, 2021
androidx.savedstate:savedstate:1.1.0 and androidx.savedstate:savedstate-ktx:1.1.0 are released. Version 1.1.0 contains these commits.
Major changes since 1.0.0
ViewTreeSavedStateRegistryOwnerAPI: A newViewTreeSavedStateRegistryOwner.get(View)API allows you to retrieve the containingSavedStateRegistrygiven aViewinstance. You must upgrade to Activity1.2.0, Fragment1.3.0, and AppCompat1.3.0-alpha01or higher to populate this correctly.savedstate-ktxartifact: The newsavedstate-ktxartifact has been added with afindViewTreeSavedStateRegistryOwner()Kotlin extension for working withViewTreeSavedStateRegistryOwner.
Version 1.1.0-rc01
December 16, 2020
androidx.savedstate:savedstate:1.1.0-rc01 and androidx.savedstate:savedstate-ktx:1.1.0-rc01 are released with no changes since 1.1.0-beta01. Version 1.1.0-rc01 contains these commits.
Version 1.1.0-beta01
October 1, 2020
androidx.savedstate:savedstate:1.1.0-beta01 and androidx.savedstate:savedstate-ktx:1.1.0-beta01 are released with no changes since 1.1.0-alpha01. Version 1.1.0-beta01 contains these commits.
Version 1.1.0-alpha01
May 20, 2020
androidx.savedstate:savedstate:1.1.0-alpha01 and androidx.savedstate:savedstate-ktx:1.1.0-alpha01 are released. Version 1.1.0-alpha01 contains these commits.
New Features
- A new
ViewTreeSavedStateRegistryOwner.get(View)API allows you to retrieve the containingSavedStateRegistrygiven aViewinstance. You must upgrade to Activity1.2.0-alpha05, Fragment1.3.0-alpha05, and AppCompat1.3.0-alpha01to populate this correctly. (aosp/1298679) - The new
savedstate-ktxartifact has been added with afindViewTreeSavedStateRegistryOwner()Kotlin extension for working withViewTreeSavedStateRegistryOwner. (aosp/1299434)
Version 1.0.0
Version 1.0.0
September 5, 2019
androidx.savedstate:savedstate:1.0.0 is released. The commits included in this version can be found here.
Major features of SavedState 1.0.0
androidx.savedstate graduated to a stable release. This is a set of APIs that allow developers to plugin components into the restore / saveInstanceState process. The main entry point of the API is SavedStateRegistry, which provides a way to retrieve previously saved states using consumeRestoredStateForKey and register a callback to registerSavedStateProvider to provide a saved state once system requests it.
Version 1.0.0-rc01
July 2, 2019
androidx.savedstate:savedstate:1.0.0-rc01 is released. The commits included in this version can be found here.
Bug fixes
- Fixed incorrect proguard rule (b/132655499)
Version 1.0.0-beta01
May 7, 2019
androidx.savedstate:savedstate:1.0.0-beta01 is released. The commits included in this version can be found here.
Version 1.0.0-alpha02
March 13, 2019
androidx.savedstate:savedstate:1.0.0-alpha02 is released. androidx.savedstate:savedstate combines artifacts androidx.savedstate:savedstate-bundle and androidx.savedstate:savedstate-common into one artifact, because it was decided to simplify savedstate infrastructure and remove generics from SavedStateRegistry. Thus, there is no need for separate modules.
The full list of commits included in this version can be found here.
New features
SavedStateRegistry.runOnNextRecreaction(Class<? extends AutoRecreated> clazz )was added. The given class will be instantiated and the methodAutoRecreated.onRecreatedwill be run when the owning component restarted.
API changes
- Generics removed from
SavedStateRegistry<T> - AbstractSavedStateRegistry & BundlableSavedStateRegistry are removed, use simple
SavedStateRegistryinstead BundleSavedStateRegistryOwneris renamed toSavedStateRegistryOwner
Version 1.0.0-alpha01
December 17, 2018
This is the first release of SavedState.
New features
androidx.savedstate is a new set of alpha APIs that allow developers to plugin components to the restore / saveInstanceState process. The main entry point of the API is SavedStateRegistry<T>, which provides a way to retrieve previously savedstate via consumeRestoredStateForKey and register a callback to registerSavedStateProvider to provide a savedstate once system requests it.