Pablichjenkov
11/08/2019, 5:38 PMkey
String parameter.
Fragment.activityViewModels(...) -> Fragment.activityViewModels(key: Any, ...)
Fragment.navGraphViewModels(...) -> Fragment.navGraphViewModels(key: Any, ...)
They both getOrCreate a new ViewModel instance based on the class
. I have 2 or more instances of the same Fragment Type in the same Activity or NavGraph. They need to have a different ViewModel instance. Using the same class
type to retrieveOrCreate a ViewModel will return the previous in path Fragment's ViewModel.
It could be avoided if each Fragment instance has a unique identifier and above methods had key: Any
overloads.
You might suggest another approach to my use case.