简体   繁体   中英

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?

use this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM