Reputation: 902
Why has ViewModelProviders been deprecated? I want to understand the reasons this class has been deprecated. Is it because google used Service Locator design pattern ( so called anti-pattern ) in it ?
Upvotes: 0
Views: 404
Reputation: 199825
If you look at the source code, you'll see that the ViewModelProviders
is nothing but a wrapper around a new constructor for 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)
.
Upvotes: 2