1

I have an Activity called Activity1, then inside has a Fragment1 all have the @ContributeAndroidInjection and then if my Activity2 wants to inject Fragment1

Why I need to implement HasAndroidInjector and do the

@Inject lateinit var androidInjector: DispatchingAndroidInjector<Any>
override fun androidInjector(): AndroidInjector<Any> = androidInjector

to be able to use a Fragment that is already with @ContributeAndroidInjection ? If I remove this two lines it says :

RunTimeException:Unable to resume activity {MyActivity}: java.lang.IllegalArgumentException: No injector factory bound for Class

I thought that if I have this:

@ContributesAndroidInjector(
 modules = [ FragmentProvider::class]
)
fun bindMyActivity2: Activity2

It would work anyways, because I've add as a modules a module that has inside the @ContributesAndroidInjector with that Fragment... Is it because I need that hasAndroidInjector when I want to provide injection into a inner Fragment?

StuartDTO
  • 783
  • 7
  • 26
  • 72
  • Is it a typo that your method `bindMyActivity2` is not abstract? – Steyrix Nov 04 '20 at 13:52
  • No, I have like `@Module interface FeatureXModule{ @ContributesAndroidInjector fun provideFragment(): MyFragment}` – StuartDTO Nov 04 '20 at 14:25
  • I may be wrong, but according to official dagger doc `@ContributesAndroidInjector` must be applied to an abstract method – Steyrix Nov 04 '20 at 14:52
  • I've tried it already... but nope. I mean I want to use a Fragment on my new Activity which has been added as a `@ContributeandroidInjector` before to use it on Activity1, so I need the presenter, repo, etc... but Adding it as a modules it would do the magic already... I don't know why I need that extra implements for hasAndroidInjection.... – StuartDTO Nov 04 '20 at 16:37
  • @Steyrix Any idea? – StuartDTO Nov 06 '20 at 11:25

0 Answers0