Join Slack
Powered by
Hi ! Maybe an easy question, but is it possible to...
# compose
l
loloof64
01/04/2022, 2:35 PM
Hi ! Maybe an easy question, but is it possible to get the context from a ViewModel subclass ?
a
annsofi
01/04/2022, 2:39 PM
There’s this specific version, don’t know how well it works with Hilt and such:
https://developer.android.com/reference/androidx/lifecycle/AndroidViewModel
👍🏾 1
l
loloof64
01/04/2022, 2:41 PM
Thank you very much 🙂 I'll try by subclassing it rather.
👍 1
c
carbaj0
01/04/2022, 3:55 PM
why do you want to have the context in your ViewModel? For me, it’s a Code Smell
👍 1
l
lesincs
01/04/2022, 4:07 PM
if you are using hilt, you can inject a context to a ViewModel
l
loloof64
01/04/2022, 9:54 PM
@carbaj0
I think you're right. In fact I wanted context to access internal files folder inside it.
loloof64
01/04/2022, 9:55 PM
@lesincs
In fact, I'm not using Hilt in my project. But thank you anyway for the suggestion.
Open in Slack
Previous
Next