Savedstate
Write pluggable components that save the UI state when a process dies, and restore it when the process restarts.
Latest Update
|
Stable Release
|
Release Candidate
|
Beta Release
|
Alpha Release
|
March 22, 2023
|
1.2.1
|
-
|
-
|
-
|
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.2.1"
// Kotlin
implementation "androidx.savedstate:savedstate-ktx:1.2.1"
}
Kotlin
dependencies {
// Java language implementation
implementation("androidx.savedstate:savedstate:1.2.1")
// Kotlin
implementation("androidx.savedstate:savedstate-ktx:1.2.1")
}
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.
Create a new issue
See the
Issue Tracker documentation
for more information.
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
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
SavedStateRegistryController
now allows early attachment of the
SavedStateRegistry
via
performAttach()
.
- You can now retrieve a previously registered
SavedStateProvider
from a
SavedStateRegistry
via
getSavedStateProvider()
.
- The
SavedState
library has been rewritten in Kotlin.
- For
SavedStateRegistryOwner
, this is a
source incompatible change
for those classes written in Kotlin - you must now override the
savedStateRegistry
property rather than implement the previous
getSavedStateRegistry()
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 on
View
of
androidx.savedstate.setViewTreeSavedStateRegistryOwner
and
androidx.savedstate.findViewTreeSavedStateRegistryOwner
to set and find a previously set owner. This replaces the
savedstate-ktx
API of
findViewTreeSavedStateRegistryOwner
.
Behavior Changes
SavedStateRegistry
no 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
SavedStateRegistryOwner
Kdocs 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 on
SavedStateRegistryController
. (
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
SavedStateRegistry
and
ViewTreeSavedStateRegistryOwner
classes have been rewritten in Kotlin. 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 on
View
of
androidx.savedstate.setViewTreeSavedStateRegistryOwner
and
androidx.savedstate.findViewTreeSavedStateRegistryOwner
to set and find a previously set owner. This replaces the
savedstate-ktx
API of
findViewTreeSavedStateRegistryOwner
. 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
SavedStateProvider
from a
SavedStateRegistry
via
getSavedStateProvider()
. (
I7ea47
,
b/215406268
)
API Changes
- The
SavedStateRegistryOwner
,
SavedStateRegistryController
, and
Recreator
classes have been rewritten in Kotlin. For
SavedStateRegistryOwner
, this is a
source incompatible change
for those classes written in Kotlin - you must now override the
savedStateRegistry
property rather than implement the previous
getSavedStateRegistry()
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
SavedStateRegistryController
now allows
early attachment of the
SavedStateRegistry
via
performAttach()
. (
Ice4bf
)
Behavior Changes
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
ViewTreeSavedStateRegistryOwner
API
: A new
ViewTreeSavedStateRegistryOwner.get(View)
API allows you to retrieve the containing
SavedStateRegistry
given a
View
instance. You must upgrade to
Activity
1.2.0
,
Fragment
1.3.0
, and
AppCompat
1.3.0-alpha01
or higher to populate this correctly.
savedstate-ktx
artifact
: The new
savedstate-ktx
artifact has been added with a
findViewTreeSavedStateRegistryOwner()
Kotlin extension for working with
ViewTreeSavedStateRegistryOwner
.
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
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
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 method
AutoRecreated.onRecreated
will be run when the owning component restarted.
API changes
- Generics removed from
SavedStateRegistry<T>
- AbstractSavedStateRegistry & BundlableSavedStateRegistry are removed, use simple
SavedStateRegistry
instead
BundleSavedStateRegistryOwner
is renamed to
SavedStateRegistryOwner
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.