Alternative for deprecated ViewModelProviders?

186 Views Asked by At

According to that Medium article here, I am using the ViewModelProviders accordingly:

myViewModel = ViewModelProviders.of(this, this.viewModeFactory).get(MyViewModel::class.java)

deprecated for me currently:

@deprecated Use the 'by viewModels()' Kotlin property delegate or

 @link ViewModelProvider#ViewModelProvider(ViewModelStoreOwner)},
 passing in the fragment.

In that article ViewModels with possible constructor arguments have a workaround where it implements the ViewModelProvider.Factory and its overridden function override fun create(//..) to provide different ViewModel arguments in a Map with Dagger.

Since I would like to learn modern technologies, I am looking for some examples with the proposed solutions?

1

There are 1 best solutions below

0
On BEST ANSWER

use this

myViewModel = ViewModelProvider(this, this.viewModeFactory).get(MyViewModel::class.java)