@Test public void twoViewModelsWithSameKey() throws Throwable { String key = "the_key"; ViewModel1 vm1 = mViewModelProvider.get(key, ViewModel1.class); assertThat(vm1.mCleared, is(false)); ViewModel2 vw2 = mViewModelProvider.get(key, ViewModel2.class); assertThat(vw2, notNullValue()); assertThat(vm1.mCleared, is(true)); }
@NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } ViewModelProvider(@NonNull ViewModelStoreOwner owner, @NonNull Factory factory);  ViewModelProvider(@NonNull ViewModelStore store, @NonNull Factory factory); }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } ViewModelProvider(@NonNull ViewModelStoreOwner owner, @NonNull Factory factory);  ViewModelProvider(@NonNull ViewModelStore store, @NonNull Factory factory); @NonNull @MainThread T get(@NonNull Class<T> modelClass); @NonNull @MainThread T get(@NonNull String key, @NonNull Class<T> modelClass); }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } ViewModelProvider(@NonNull ViewModelStoreOwner owner, @NonNull Factory factory);  ViewModelProvider(@NonNull ViewModelStore store, @NonNull Factory factory); @NonNull @MainThread T get(@NonNull Class<T> modelClass); @NonNull @MainThread T get(@NonNull String key, @NonNull Class<T> modelClass);  }