简体   繁体   English

为什么 ViewModelProviders 已被弃用?

[英]Why has ViewModelProviders been deprecated?

Why has ViewModelProviders been deprecated?为什么 ViewModelProviders 已被弃用? I want to understand the reasons this class has been deprecated.我想了解这个 class 已被弃用的原因。 Is it because google used Service Locator design pattern ( so called anti-pattern ) in it?是因为谷歌在其中使用了服务定位器设计模式(所谓的反模式)吗?

If you look at the source code , you'll see that the ViewModelProviders is nothing but a wrapper around a new constructor for ViewModelProvider :如果您查看源代码,您会发现ViewModelProviders只不过是ViewModelProvider的新构造函数的包装器:

public static ViewModelProvider of(@NonNull Fragment fragment) {
    return new ViewModelProvider(fragment);
}

So, as per the deprecation message, just use new ViewModelProvider(this) instead of ViewModelProviders.of(this) .因此,根据弃用消息,只需使用new ViewModelProvider(this)而不是ViewModelProviders.of(this)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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