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
  • 32,901
  • 14
  • 106
  • 130
wioskamala
  • 1,021
  • 1
  • 10
  • 14

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
  • 527
  • 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? – wioskamala May 04 '17 at 20:04