android - Dagger 2 : Presenter is null -
need assistance in understanding why splash presenter returned null. following clean architecture.
public class splashactivity extends baseactivity implements hascomponent<logincomponent> { @inject splashpresenter splashpresenter; private logincomponent logincomponent; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_indeterminate_progress); //setcontentview(r.layout.spla); this.initializeinjector(); if (savedinstancestate == null) { // addfragment(r.id.fragmentcontainer, new userlistfragment()); } splashpresenter.initialize(); } private void initializeinjector() { this.logincomponent = daggerlogincomponent.builder() .applicationcomponent(getapplicationcomponent()) .activitymodule(getactivitymodule()) .loginmodule(new loginmodule()) .build(); } @override public logincomponent getcomponent() { return logincomponent; } }
in activity splashpresenter null.
here activity component
@peractivity @component(dependencies = applicationcomponent.class, modules = activitymodule.class) public interface activitycomponent { //exposed sub-graphs. activity activity(); } @module public class activitymodule { private final activity activity; public activitymodule(activity activity) { this.activity = activity; } /** * expose activity dependents in graph. */ @provides @peractivity activity activity() { return this.activity; } }
here logincomponent
@peractivity @component(dependencies = applicationcomponent.class, modules = {activitymodule.class, loginmodule.class}) public interface logincomponent extends activitycomponent { }
here loginmodule
@module public class loginmodule { private user user; public loginmodule(){} public loginmodule(user user){this.user = user;} @provides loginrepository provideloginrepository(logindatarepository loginrepository) { return loginrepository; } @provides @peractivity @named("isuserloggedin") usecase provideisuserloggedinusecase(isuserloggedin isuserloggedin){ return isuserloggedin; } @provides @peractivity @named("login") usecase provideloginusecase(loginrepository loginrepository, threadexecutor threadexecutor, postexecutionthread postexecutionthread){ return new login(user,loginrepository,threadexecutor,postexecutionthread); } @provides @peractivity @named("logout") usecase providelogoutusecase(loginrepository loginrepository, threadexecutor threadexecutor, postexecutionthread postexecutionthread){ return new logout(user,loginrepository,threadexecutor,postexecutionthread); } }
in baseactivity doing following
public abstract class baseactivity extends activity { @inject navigator navigator; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.getapplicationcomponent().inject(this); } protected activitymodule getactivitymodule() { return new activitymodule(this); } }
still unable understand why presenter null in splashactivity
here splash presenter
@peractivity public class splashpresenter implements presenter { private final usecase isuserloggedin; private splashview splashview; @inject public splashpresenter(@named("isuserloggedin") usecase isuserloggedin) { this.isuserloggedin = isuserloggedin; } }
the instance of logincomponent
creates after inject method
.
move component initializer custom application class. or move component initializer baseactivity
, inject method
slashactivity
and makes inject declaration
each activity want inject instance @ component interface.