1

Previously I had something like this:

((MyApp) getApplication()).getApplicationComponent())
        .newMyActivitySubcomponent(new MyActivityModule(this))
        .inject(this);
      (...)
}

Now I have only:

AndroidInjection.inject(this);

How can I have different subcomponents/components for different activities?

David Medenjak
  • 33,993
  • 14
  • 106
  • 134
RCH
  • 1,247
  • 1
  • 11
  • 16

1 Answers1

0

Unless I am mistaken, the proper way to do this is by utilizing "ActivityScopes" (more information found here: http://frogermcs.github.io/dependency-injection-with-dagger-2-custom-scopes/).

If I understand this correctly, you must create a different component for each activity for which you wish to use a different module, and then add whatever module you wish to use with the activity matched to each component with said component.

John Gallagher
  • 525
  • 4
  • 15
  • Let's say that I want to use that newMyActivitySubcomponent in 2 out of 5 activities in my application. How can I do this in dagger 2.10? – RCH May 04 '17 at 20:04