[英]Alternative for deprecated ViewModelProviders?
根据这里的 Medium 文章,我相应地使用了ViewModelProviders
:
myViewModel = ViewModelProviders.of(this, this.viewModeFactory).get(MyViewModel::class.java)
目前对我来说已弃用:
@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.
由于我想学习现代技术,我正在寻找一些建议解决方案的例子?
用这个
myViewModel = ViewModelProvider(this, this.viewModeFactory).get(MyViewModel::class.java)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.