How do you handle dagger scoping using single activity Achi. Let's say I'd like to share a viewmodel amongst my reg fragments. How do I do it without creating another activity?
t
tjohnn
12/14/2019, 1:54 PM
Probably a parent fragment? There has to be a lifecycle owner that both fragments have in common
s
sanmi
12/14/2019, 2:37 PM
A parent fragment is that even possible. I understand that. If I scope it to the main activity. That instance will be retained mostly through out the app.
t
tjohnn
12/14/2019, 4:01 PM
Yes it’s possible, I did use parent fragment scopes for steppers sometimes ago
g
ghedeon
12/14/2019, 10:27 PM
The "official" suggestion is to use shared viewmodel but as usual with "official" suggestions it has very poor practicality. You might want to consider dagger scopes instead.
s
sanmi
12/16/2019, 3:18 PM
Nice! Please can you show me a resource on how to go about it Tosin?
Ghedoen, I am using dagger scope with single activity at the moment.
t
tjohnn
12/16/2019, 4:11 PM
Not sure of a resource right now.
You would have a parent fragment module and have an @Provides method for the ViewModel created inside the module and you will have the @ContributesAndroidInjector for the child fragments inside it also, from there you can inject the ViewModel inside any of the fragments.