Pavel Pipovic
Pavel Pipovic

Reputation: 359

Alternative for deprecated ViewModelProviders?

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?

Upvotes: 0

Views: 227

Answers (1)

SebastienRieu
SebastienRieu

Reputation: 1512

use this

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

Upvotes: 0

Related Questions