you can use such qualifiers. two separate files define the following:
@Qualifier @Retention(RetentionPolicy.RUNTIME) public @interface ActivityContext { } @Qualifier @Retention(RetentionPolicy.RUNTIME) public @interface ApplicationContext { }
then in your ActivityModule do the following:
@Provides @ActivityScope @ActivityContext public Context context() { return activity; }
as well as in your application:
@Provides @Singleton @ApplicationContext Context provideApplicationContext() { return app.getApplicationContext(); }
we now have a way to specify any type of context that we need, based on the @ApplicationContext and @ActivityContext classifiers.
so, for example, in your work you could do this:
@Inject @ApplicationContext Context c;
which will enter the application context.
and in the module you can do this, for example:
@Provides @ActivityScope LoginPresenter provideLoginPresenter(@ActivityContext Context context) { return new LoginPresenter(context); }
to provide an activity context. this is just an example.
source share