Google berkomitmen untuk mendorong terwujudnya keadilan rasial bagi komunitas Kulit Hitam. Lihat caranya.

androidx.ui.viewmodel

Top-level functions summary

VM
viewModel(key: String? = null, factory: Factory? = null)

Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity)

VM
viewModel(modelClass: Class<VM>, key: String? = null, factory: Factory? = null)

Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity)

Top-level functions

viewModel

@Composable inline fun <reified VM : ViewModel> viewModel(
    key: String? = null,
    factory: Factory? = null
): VM

Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity)

The created ViewModel is associated with the given scope and will be retained as long as the scope is alive (e.g. if it is an activity, until it is finished or process is killed).

Parameters
key: String? = null The key to use to identify the ViewModel.
Return
A ViewModel that is an instance of the given VM type.

viewModel

@Composable fun <VM : ViewModel> viewModel(
    modelClass: Class<VM>,
    key: String? = null,
    factory: Factory? = null
): VM

Returns an existing ViewModel or creates a new one in the scope (usually, a fragment or an activity)

The created ViewModel is associated with the given scope and will be retained as long as the scope is alive (e.g. if it is an activity, until it is finished or process is killed).

Parameters
modelClass: Class<VM> The class of the ViewModel to create an instance of it if it is not present.
key: String? = null The key to use to identify the ViewModel.
Return
A ViewModel that is an instance of the given VM type.