-
public final class FragmentViewModelContext extends ViewModelContext
The ViewModelContext for a ViewModel created with a fragment scope (
val viewModel by fragmentViewModel<MyViewModel>).The owner and savedStateRegistry default to the Fragment as the provider, if you need to use an alternative source for the ViewModelStoreOwner and/or SavedStateRegistry; such in the case of JetPack Navigation Component destinations with ViewModels, then you can provided them via this context.
-
-
Constructor Summary
Constructors Constructor Description FragmentViewModelContext(ComponentActivity activity, Object args, Fragment fragment, ViewModelStoreOwner owner, SavedStateRegistry savedStateRegistry)
-
Method Summary
Modifier and Type Method Description ComponentActivitygetActivity()The activity which is using the ViewModel. ObjectgetArgs()Fragment arguments set via Mavericks.KEY_ARG. final FragmentgetFragment()The fragment owner of the ViewModel. final <F extends Fragment> Ffragment()Convenience method to type fragment. -
-
Constructor Detail
-
FragmentViewModelContext
FragmentViewModelContext(ComponentActivity activity, Object args, Fragment fragment, ViewModelStoreOwner owner, SavedStateRegistry savedStateRegistry)
-
-
Method Detail
-
getActivity
ComponentActivity getActivity()
The activity which is using the ViewModel.
-
getArgs
Object getArgs()
Fragment arguments set via Mavericks.KEY_ARG.
-
getFragment
final Fragment getFragment()
The fragment owner of the ViewModel.
-
-
-
-