https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
j

jonasb

06/27/2019, 12:17 PM
Hey! I have some problems wrapping my head around why
by viewModels()
(part of Android KTX) requires a viewmodel factory provider as opposed to a viewmodel factory. I.e. I would prefer to be able to write
val vm by viewModels { MyViewModel(arg1, arg2) }
. Is there anything I’m missing where making the viewmodel factory as explicit as it is now is of great benefit?
p

pavi2410

07/02/2019, 5:47 PM
If there had been such a thing like this
val vm by viewModels { MyViewModel(arg1, arg2) }
MyViewModel(arg1, arg2)
would create a new object otherwise, which should be created using ViewModelProviders. I would rather require them to be like
val vm by viewModels<MyViewModel>(arg1, arg2)
3 Views