{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

AndroidViewModel

open class AndroidViewModel : ViewModel

kotlin.Any
   ↳ androidx.lifecycle.ViewModel
     ↳ androidx.lifecycle.AndroidViewModel

Application context aware ViewModel.

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

Summary

Public constructors

Public functions

open T

Return the application.

Inherited functions

From androidx.lifecycle.ViewModel
open Unit
addCloseable(closeable: Closeable)

Add a new Closeable object that will be closed directly before onCleared is called.

open Unit

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

Public constructors

AndroidViewModel

AndroidViewModel(application: Application)

Public functions

getApplication

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

Return the application.