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
Dagger Android is designed in a specific way where Application holds the top most level component that knows about Android components such as Activity, Service, etc. When AndroidInjection.inject(this) is called in an Activity, Dagger will try to get instance of AndroidInjector<Activity> from the Application class, which is injected by the Application Component normally.
So we're left with the following hierarchy of Dagger components:
Application Component -> Activity Sub Component -> Fragment Sub Component
What you're asking for is not possible in the above hierarchy, which is the common hierarchy Dagger Android is set up. You might be able to stick in another component between Application component and Activity component, but it will basically be a hack. An example of such hack is available here.
I'd strongly recommend against hacks and instead change your UI architecture to use multiple Fragments under the same Activity to achieve what you want. It is possible to do it with Fragments since they support nesting of Fragments. So you can have the following hierarch with fragments:
Application Component -> Activity Sub Component -> Fragment Sub Component -> Fragment Sub Component -> and so on.
Hi, Would you be willing to show how to create a feature with multiple activities and a resource shared only with the activities of this feature ?
The text was updated successfully, but these errors were encountered: