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

paulex

12/16/2020, 12:29 PM
Looking for a clean way to do it without passing context to the viewModel
s

Sinan Gunes

12/16/2020, 12:32 PM
I think passing application context should be fine.
p

paulex

12/16/2020, 12:32 PM
Isn’t that a bad practice
I believe the viewModel shouldn’t hold reference to Android classes like activity and context etc
s

Sinan Gunes

12/16/2020, 12:34 PM
have you seen
AndroidViewModel
?
p

paulex

12/16/2020, 12:35 PM
Let me check that out
s

Sinan Gunes

12/16/2020, 12:35 PM
activity and its context is bad practice because it will cause leaks. passing application should be fine.
p

paulex

12/16/2020, 12:35 PM
Okay cool
s

Sinan Gunes

12/16/2020, 12:35 PM
application will outlive viewModels anyway.