Created
March 16, 2020 15:56
-
-
Save Pluu/c1de6e10a1d768f5b960353018402a8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ViewModelProvider { | |
... | |
private final Factory mFactory; | |
private final ViewModelStore mViewModelStore; | |
// ① Use ViewModelStoreOwner | |
public ViewModelProvider(@NonNull ViewModelStoreOwner owner) { | |
this(owner.getViewModelStore(), owner instanceof HasDefaultViewModelProviderFactory | |
? ((HasDefaultViewModelProviderFactory) owner).getDefaultViewModelProviderFactory() | |
: NewInstanceFactory.getInstance()); | |
} | |
// ② Use ViewModelStoreOwner, Factory | |
public ViewModelProvider(@NonNull ViewModelStoreOwner owner, @NonNull Factory factory) { | |
this(owner.getViewModelStore(), factory); | |
} | |
// ③ Use ViewModelStore, Factory | |
public ViewModelProvider(@NonNull ViewModelStore store, @NonNull Factory factory) { | |
mFactory = factory; | |
mViewModelStore = store; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment