AndroidViewModel



Application context aware ViewModel.

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

Summary

Public constructors

android

Public functions

open T

Return the application.

android

Extension properties

Application

The underlying Application inside 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

Return the application.

Extension properties

application

val AndroidViewModel.applicationApplication

The underlying Application inside AndroidViewModel

One common hierarchy, such as KotlinViewModel <: JavaViewModel <: AndroidViewModel, exposes private property application incorrectly. It is now fixed in K2 (Kotlin language version 2.0), but not backward compatible. This inline extension will make compilations of both pre- and post- 2.0 go well.