Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

AndroidViewModelFactory

open class AndroidViewModelFactory : ViewModelProvider.NewInstanceFactory
kotlin.Any
   ↳ androidx.lifecycle.ViewModelProvider.NewInstanceFactory
   ↳ androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory

Factory which may create AndroidViewModel and ViewModel, which have an empty constructor.

Summary

Public constructors
<init>(@NonNull application: Application)

Creates a AndroidViewModelFactory

Public methods
open T
create(@NonNull modelClass: Class<T>)

open static ViewModelProvider.AndroidViewModelFactory
getInstance(@NonNull application: Application)

Retrieve a singleton instance of AndroidViewModelFactory.

Public constructors

<init>

AndroidViewModelFactory(@NonNull application: Application)

Creates a AndroidViewModelFactory

Parameters
application Application: an application to pass in AndroidViewModel

Public methods

create

@NonNull open fun <T : ViewModel!> create(@NonNull modelClass: Class<T>): T

getInstance

@NonNull open static fun getInstance(@NonNull application: Application): ViewModelProvider.AndroidViewModelFactory

Retrieve a singleton instance of AndroidViewModelFactory.

Parameters
application Application: an application to pass in AndroidViewModel
Return
ViewModelProvider.AndroidViewModelFactory: A valid AndroidViewModelFactory