AndroidViewModel


public class AndroidViewModel extends ViewModel


Application context aware ViewModel.

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

Summary

Public constructors

Public methods

@NonNull T
<T extends Application> getApplication()

Return the application.

Extension functions

final @NonNull Application

The underlying Application inside AndroidViewModel

Inherited methods

From androidx.lifecycle.ViewModel
void
final void
final T
void

Public constructors

AndroidViewModel

Added in 2.0.0
public AndroidViewModel(@NonNull Application application)

Public methods

getApplication

Added in 2.0.0
public @NonNull T <T extends Application> getApplication()

Return the application.

Extension functions

AndroidViewModelKt.getApplication

public final @NonNull Application AndroidViewModelKt.getApplication(@NonNull AndroidViewModel receiver)

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.