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.

Inherited methods

From androidx.lifecycle.ViewModel
void

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

final void

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

final @Nullable T
<T extends Closeable> getCloseable(@NonNull String key)

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

void

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

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.