You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for open sourcing this library.
In my project, I've viewmodels which extend AndroidViewModel class, which means they want an
instance of application as a constructor parameter. I use the application context in viewmodel for two purposes:
to get some an instance of my application class to further have access to my dagger applicationComponent field so that I can use field injection in my viewmodel. Something like this:
okay, I read about it and got to know that it's a bad practice to resolve the resources in viewmodels.we should just be setting int resource id there.
So we can eliminate the second use there.
okay I read more about first thing :) , and got to know implementing a custom view model factory is the way to provide all the dependencies to viewmodel. So, it turns out that I can get rid of the context itself here. I am.gonna try it.
Hi,
First of all, thanks for open sourcing this library.
In my project, I've viewmodels which extend
AndroidViewModel
class, which means they want aninstance of
application
as a constructor parameter. I use the application context in viewmodel for two purposes:applicationComponent
field so that I can use field injection in my viewmodel. Something like this:MyApplication.getInstance(application).applicationComponent.inject(this)
(getApplication() as MyApplication).getString(R.string....
Hope that's clear.
I can't think of anyway to test this viewmodel without using Android instrumention/RoboElectric.
Do you have any ideas in mind?
The text was updated successfully, but these errors were encountered: