ViewTreeViewModelStoreOwner

Added in 2.3.0

public final class ViewTreeViewModelStoreOwner


Summary

Public methods

static final ViewModelStoreOwner
get(@NonNull View receiver)

Retrieves the ViewModelStoreOwner associated with the given View.

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

Sets the ViewModelStoreOwner associated with the given View.

Public methods

public static final ViewModelStoreOwner get(@NonNull View receiver)

Retrieves the ViewModelStoreOwner associated with the given View.

Used to retain state associated with this view across configuration changes.

Returns
ViewModelStoreOwner

ViewModelStoreOwner associated with this view or its ancestors

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

Sets the ViewModelStoreOwner associated with the given View.

Calls to findViewTreeViewModelStoreOwner from this view or its descendants will return viewModelStoreOwner.

This should only be called by constructs such as Activitys or Fragments that manage a view tree and retain state through a ViewModelStoreOwner. Callers should only set a ViewModelStoreOwner that is 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 to associate with this View