SavedStateRegistryOwner


public interface SavedStateRegistryOwner extends LifecycleOwner

Known direct subclasses
ComponentActivity

Base class for activities that enables composition of higher level components.

ComponentDialog

Base class for dialogs that enables composition of higher level components.

Fragment

Static library support version of the framework's android.app.Fragment.

NavBackStackEntry

Representation of an entry in the back stack of a androidx.navigation.NavController.

Known indirect subclasses
AbstractListDetailFragment

A fragment supports adaptive two-pane layout.

AbstractProgressFragment

The base class for Fragments that handle dynamic feature installation.

AlertDialog

A subclass of Dialog that can display one, two or three buttons.

AmbientModeSupport

This class is deprecated.

Use AmbientLifecycleObserver instead.

AppCompatActivity

Base class for activities that wish to use some of the newer platform features on older Android devices.

AppCompatDialogFragment

A special version of DialogFragment which uses an AppCompatDialog in place of a platform-styled dialog.

AppCompatDialog

Base class for AppCompat themed android.app.Dialogs.

BaseCarAppActivity

Core logic for CarAppLibrary Activity interaction with a host.

BaseLeanbackPreferenceFragmentCompat

This fragment provides a preference fragment with leanback-style behavior, suitable for embedding into broader UI elements.

BaseSupportFragment

Base class for leanback Fragments.

BrandedSupportFragment

Fragment class for managing search and branding using a view that implements TitleViewAdapter.Provider.

BrowseSupportFragment

A fragment for creating Leanback browse screens.

CarAppActivity

The class representing a car app activity in the main display.

DefaultProgressFragment

The default androidx.fragment.app.Fragment to display during installation progress.

DetailsSupportFragment

A fragment for creating Leanback details screens.

DialogFragment

A fragment that displays a dialog window, floating in the foreground of its activity's window.

DynamicNavHostFragment

The NavHostFragment for dynamic features.

EditTextPreferenceDialogFragmentCompat
ErrorSupportFragment

A fragment for displaying an error indication.

FragmentActivity

Base class for activities that want to use the support-based Fragments.

GuidedStepSupportFragment

A GuidedStepSupportFragment is used to guide the user through a decision or series of decisions.

HeadersSupportFragment

An fragment containing a list of row headers.

LauncherActivity

This class handles providing the right launcher activity when running native applications and Car App Library applications.

LeanbackEditTextPreferenceDialogFragmentCompat

Implemented a dialog to input text.

LeanbackListPreferenceDialogFragmentCompat

Implemented a dialog to show ListPreference or MultiSelectListPreference.

LeanbackPreferenceDialogFragmentCompat

A fragment that shows DialogPreference, for example or androidx.preference.MultiSelectListPreference.

LeanbackPreferenceFragmentCompat

This fragment provides a fully decorated leanback-style preference fragment, including a list background and header.

LeanbackSettingsFragmentCompat

This fragment provides a container for displaying a LeanbackPreferenceFragmentCompat

ListFragment

Static library support version of the framework's android.app.ListFragment.

ListPreferenceDialogFragmentCompat
MediaRouteChooserDialogFragment

Media route chooser dialog fragment.

MediaRouteChooserDialog

This class implements the route chooser dialog for MediaRouter.

MediaRouteControllerDialogFragment

Media route controller dialog fragment.

MediaRouteControllerDialog

This class implements the route controller dialog for MediaRouter.

MediaRouteDiscoveryFragment

Media route discovery fragment.

MultiSelectListPreferenceDialogFragmentCompat
NavHostFragment

NavHostFragment provides an area within your layout for self-contained navigation to occur.

OnboardingSupportFragment

An OnboardingSupportFragment provides a common and simple way to build onboarding screen for applications.

PdfViewerFragment

A Fragment that renders a PDF document.

PlaybackSupportFragment

A fragment for displaying playback controls and related content.

PreferenceDialogFragmentCompat

Abstract base class which presents a dialog associated with a DialogPreference.

PreferenceFragmentCompat

A PreferenceFragmentCompat is the entry point to using the Preference library.

PreferenceHeaderFragmentCompat

PreferenceHeaderFragmentCompat implements a two-pane fragment for preferences.

RowsSupportFragment

An ordered set of rows of leanback widgets.

SdkActivity

Activity to start for SDKs running locally.

SearchSupportFragment

A fragment to handle searches.

VerticalGridSupportFragment

A fragment for creating leanback vertical grids.

VideoSupportFragment

Subclass of PlaybackSupportFragment that is responsible for providing a SurfaceView and rendering video.


A scope that owns SavedStateRegistry

This owner should be passed in to create a SavedStateRegistryController object through which this owner can access and perform operations via the controller's SavedStateRegistry

SavedStateRegistryController.performAttach must be called once (and only once) on the main thread during the owner's Lifecycle.State.INITIALIZED state. It should be called before you call SavedStateRegistryController.performRestore

SavedStateRegistryController.performRestore can be called with a nullable if nothing needs to be restored, or with the SavedState to be restored. performRestore can be called in one of two places:

  1. Directly before the Lifecycle moves to Lifecycle.State.CREATED

  2. Before Lifecycle.State.STARTED is reached, as part of the LifecycleObserver that is added during owner initialization

SavedStateRegistryController.performSave should be called after owner has been stopped but before it reaches Lifecycle.State.DESTROYED state. Hence it should only be called once the owner has received the Lifecycle.Event.ON_STOP event. The SavedState passed to performSave will be the SavedState restored by performRestore.

Summary

Public methods

abstract @NonNull SavedStateRegistry

The SavedStateRegistry owned by this SavedStateRegistryOwner

Extension functions

default final @NonNull ReadWriteProperty<Object, @NonNull T>
<T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

default final @NonNull ReadWriteProperty<Object, @NonNull T>
<T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull String key,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

default final @NonNull ReadWriteProperty<Object, @NonNull T>
<T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

default final @NonNull ReadWriteProperty<Object, @NonNull T>
<T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull String key,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

Inherited methods

From androidx.lifecycle.LifecycleOwner
abstract @NonNull Lifecycle

Returns the Lifecycle of the provider.

Public methods

getSavedStateRegistry

Added in 1.0.0
abstract @NonNull SavedStateRegistry getSavedStateRegistry()

The SavedStateRegistry owned by this SavedStateRegistryOwner

Extension functions

SavedStateRegistryOwnerDelegatesKt.saved

default final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

This is a convenience overload that uses the serializer function to obtain the serializer for the reified type T.

The name of the property will be used as the key for storing the value in the SavedStateRegistry.

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by saved { User(id = 123, name = "John Doe") }
}
Parameters
@NonNull Function0<@NonNull T> init

The function to provide the initial value of the property.

Returns
@NonNull ReadWriteProperty<Object, @NonNull T>

A property delegate provider that manages the saving and restoring of the value.

SavedStateRegistryOwnerDelegatesKt.saved

default final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull String key,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by saved(key = "myKey") { User(id = 123, name = "John Doe") }
}
Parameters
@NonNull String key

The String key to use for storing the value in the SavedStateRegistry.

@NonNull Function0<@NonNull T> init

The function to provide the initial value of the property.

Returns
@NonNull ReadWriteProperty<Object, @NonNull T>

A property delegate provider that manages the saving and restoring of the value.

SavedStateRegistryOwnerDelegatesKt.saved

default final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

This is a convenience overload that uses the name of the property as the key for storing the value in the SavedStateRegistry

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by saved(serializer = serializer()) { User(id = 123, name = "John Doe") }
}
Parameters
@NonNull <Error class: unknown class><@NonNull T> serializer

The KSerializer to use for serializing and deserializing the value.

@NonNull Function0<@NonNull T> init

The function to provide the initial value of the property.

Returns
@NonNull ReadWriteProperty<Object, @NonNull T>

A property delegate provider that manages the saving and restoring of the value.

SavedStateRegistryOwnerDelegatesKt.saved

default final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> SavedStateRegistryOwnerDelegatesKt.saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull String key,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by
        saved(key = "myKey", serializer = serializer()) { User(id = 123, name = "John Doe") }
}
Parameters
@NonNull String key

The String key to use for storing the value in the SavedStateRegistry.

@NonNull <Error class: unknown class><@NonNull T> serializer

The KSerializer to use for serializing and deserializing the value.

@NonNull Function0<@NonNull T> init

The function to provide the initial value of the property.

Returns
@NonNull ReadWriteProperty<Object, @NonNull T>

A property delegate provider that manages the saving and restoring of the value.