Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature with multiple activities #1

Open
juliocbcotta opened this issue Apr 3, 2017 · 1 comment
Open

Feature with multiple activities #1

juliocbcotta opened this issue Apr 3, 2017 · 1 comment

Comments

@juliocbcotta
Copy link

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 ?

@Nimrodda
Copy link
Owner

Nimrodda commented Jul 8, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants