I have my component like
@GithubListActivityScope
@Component(modules = { GithubListActivityModule.class,GlideActivityModule.class })
public interface GithubListActivityComponent {
GithubUserListAdapter githubUserListAdapter ( );
RequestManager requestManager();
LinearLayoutManager linearLayoutManager();
}
@Module
public class GithubListActivityModule {
private final Activity githubListActivity;
public GithubListActivityModule ( Activity activity ) {
this.githubListActivity = activity;
}
@Provides
@GithubListActivityScope
Activity activity ( ) {
return this.githubListActivity;
}
@Provides
@GithubListActivityScope
public LinearLayoutManager linearLayoutManager(Activity activity){
return new LinearLayoutManager ( activity );
}
}
@GithubListActivityScope
@Inject
LinearLayoutManager linearLayoutManager;
githubListActivityComponent = DaggerGithubListActivityComponent.builder ()
.githubListActivityModule ( new GithubListActivityModule ( this ) )
.build ();
linearLayoutManager = githubListActivityComponent.linearLayoutManager ();
Everywhere that I am passing Activity
, I should pass exactly the same class Name (not its parent) So once edited every parameters and return types that were "Activity"
into "GithubListActivity"
and then added
void inject( GithubListActivity activity);
inside the component class
then injected "GithubListActivity"
like this :
DaggerGithubListActivityComponent.builder ()
.githubListActivityModule ( new GithubListActivityModule ( this ) )
.build ().inject ( this );
Then the codes worked for me ..
Lesson :
1. Define inject method and Inject the current Activity
2. Use exactly the same type of object (not the parent ) in this case use "GithubListActivity" instead of just activity.