ViewTreeViewModelStoreOwner

Added in 2.3.0

public final class ViewTreeViewModelStoreOwner


Summary

Public methods

static final ViewModelStoreOwner
get(@NonNull View receiver)

Retrieve the ViewModelStoreOwner associated with the given View.

static final void
set(@NonNull View receiver, ViewModelStoreOwner viewModelStoreOwner)

Set the ViewModelStoreOwner associated with the given View.

Public methods

public static final ViewModelStoreOwner get(@NonNull View receiver)

Retrieve the ViewModelStoreOwner associated with the given View. This may be used to retain state associated with this view across configuration changes.

Returns
ViewModelStoreOwner

The ViewModelStoreOwner associated with this view and/or some subset of its ancestors

public static final void set(@NonNull View receiver, ViewModelStoreOwner viewModelStoreOwner)

Set the ViewModelStoreOwner associated with the given View. Calls to get from this view or descendants will return viewModelStoreOwner.

This should only be called by constructs such as activities or fragments that manage a view tree and retain state through a ViewModelStoreOwner. Callers should only set a ViewModelStoreOwner that will be stable. The associated ViewModelStore should be cleared if the view tree is removed and is not guaranteed to later become reattached to a window.

Parameters
ViewModelStoreOwner viewModelStoreOwner

ViewModelStoreOwner associated with the given view