ActivityViewModelContext

data class ActivityViewModelContext(activity: ComponentActivity, args: Any?, owner: ViewModelStoreOwner, savedStateRegistry: SavedStateRegistry) : ViewModelContext

The ViewModelContext for a ViewModel created with an activity scope (val viewModel by activityViewModel<MyViewModel>). Although a fragment reference is available when an activity scoped ViewModel is first created, during process restoration, activity scoped ViewModels will be created without a fragment reference, so it is only safe to reference the activity.

Constructors

ActivityViewModelContext
Link copied to clipboard
fun ActivityViewModelContext(activity: ComponentActivity, args: Any?, owner: ViewModelStoreOwner = activity, savedStateRegistry: SavedStateRegistry = activity.savedStateRegistry)

Functions

activity
Link copied to clipboard
fun <A : ComponentActivity> activity(): A

Convenience method to type activity.

app
Link copied to clipboard
fun <A : Application> app(): A

Convenience method to access a typed Application.

args
Link copied to clipboard
fun <A> args(): A

Convenience method to type args.

Properties

activity
Link copied to clipboard
open override val activity: ComponentActivity

The activity which is using the ViewModel.

args
Link copied to clipboard
open override val args: Any?

Fragment arguments set via Mavericks.KEY_ARG.