AndroidViewModel

open class AndroidViewModel : ViewModel


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.

Unit
addCloseable(key: String, closeable: Closeable)

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

T?

Returns the closeable previously added with addCloseable with the given key.

open Unit

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

Public constructors

AndroidViewModel

Added in 2.0.0
AndroidViewModel(application: Application)

Public functions

getApplication

Added in 2.0.0
open fun <T : Application> getApplication(): T

Return the application.