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
android
Unit
addCloseable(key: String, closeable: AutoCloseable)
android
T?
android
open Unit
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.