AndroidViewModel



ViewModel that has access to the Application context.

Subclasses must have a constructor that accepts Application as the only parameter.

See also
ViewModel

Summary

Public constructors

android

Public functions

open T

Returns the Application instance.

android

Extension properties

Application

Returns the underlying Application of the AndroidViewModel.

android

Inherited functions

From androidx.lifecycle.ViewModel
open Unit

Adds an AutoCloseable resource to this ViewModel.

android
Unit
addCloseable(key: String, closeable: AutoCloseable)

Adds an AutoCloseable resource with an associated key to this ViewModel.

android
T?

Returns the AutoCloseable resource associated to the given key, or null if such a key is not present in this ViewModel.

android
open Unit

This method will be called when this ViewModel is no longer used and will be destroyed.

android

Public constructors

AndroidViewModel

AndroidViewModel(application: Application)

Public functions

getApplication

open fun <T : Application> getApplication(): T

Returns the Application instance.

Extension properties

AndroidViewModel.application

val AndroidViewModel.applicationApplication

Returns the underlying Application of the AndroidViewModel.

Works around a Kotlin compilation issue where class hierarchies extending AndroidViewModel (e.g., KotlinViewModel extending JavaViewModel extending AndroidViewModel) incorrectly expose the private application property.