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

AndroidViewModel

public class AndroidViewModel extends ViewModel

java.lang.Object
   ↳ 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 methods

@NonNull T
<T extends Application> getApplication()

Return the application.

Inherited methods

From androidx.lifecycle.ViewModel
void

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

void

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

Public constructors

AndroidViewModel

public AndroidViewModel(@NonNull Application application)

Public methods

getApplication

public @NonNull T <T extends Application> getApplication()

Return the application.