android - Dagger2 Component as Static Global Variable -


my android app has multiple activities. mainactivity constructs dagger2 component in oncreate() method , assigns static variable class can call static method mainactivity.getdaggercomponent() inject dependencies.

the problem i'm discovering when start videoplayeractivity, mainactivity object gets onpause() invoked. if happens, static component variable gets set null. @ later point, videoplayeractivity needs inject dependencies, there no component things blow up.

how 1 ensure dagger2 component available @ times activities?

initialize dagger component in application class or statically. might you're doing wrong thing trying use dependencies of 1 activity in activity. might create memory leaks , in particular sounds design problem. if first activity destroyed? free dagger instance? why graph belongs first activity , not second one? if user enter app second activity - first 1 won't initialized. , on, , on.

if still need activity instance, should use activity specific component within activity , move else in global (application wide) component.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -