ViewTreeViewModelStoreOwner
open class ViewTreeViewModelStoreOwner
kotlin.Any | |
↳ | androidx.lifecycle.ViewTreeViewModelStoreOwner |
Accessors for finding a view tree-local ViewModelStoreOwner
that allows access to a ViewModelStore
for the given view.
Summary
Public methods | |
---|---|
open static ViewModelStoreOwner? |
Retrieve the |
open static Unit |
set(@NonNull view: View, @Nullable viewModelStoreOwner: ViewModelStoreOwner?) Set the |
Public methods
get
@Nullable open static fun get(@NonNull view: View): ViewModelStoreOwner?
Retrieve the ViewModelStoreOwner
associated with the given View
. This may be used to retain state associated with this view across configuration changes.
Parameters | |
---|---|
view |
View: View to fetch a ViewModelStoreOwner for |
Return | |
---|---|
ViewModelStoreOwner? |
The ViewModelStoreOwner associated with this view and/or some subset of its ancestors |
set
open static fun set(
@NonNull view: View,
@Nullable viewModelStoreOwner: ViewModelStoreOwner?
): Unit
Set the ViewModelStoreOwner
associated with the given View
. Calls to get(View)
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 | |
---|---|
view |
View: Root view associated with the viewModelStoreOwner |
viewModelStoreOwner |
ViewModelStoreOwner?: ViewModelStoreOwner associated with the given view |