https://kotlinlang.org logo
#android
Title
# android
s

scottiedog45

08/08/2019, 1:20 AM
how does a ViewModel provider (something like
Copy code
singleLargeTextInputViewModel = ViewModelProviders.of(this, SingleLargeInputViewModel.FACTORY(NetworkService())).get(
            SingleLargeInputViewModel::class.java
        )
) “know” (????) that a view model already exists? Or would it?
a

Adam Powell

08/08/2019, 1:28 AM
it fetches the
ViewModelStore
from the activity or fragment you gave it, which is tied into the nonConfigurationInstance mechanism of activity recreation. It just passes a map from old to new activity instance and stores viewmodels for you
s

scottiedog45

08/08/2019, 1:50 AM
Oh cool! I had no idea about the nonConfigurationInstance or that viewModelStore was a thing activities/fragments had.