How to manage the lifecycle of Dagger2 components?


I am learning Dagger 2, want to use it with Single Activity and MVP approach.
The following questions arose:

  1. I want the presenter of some fragments to stay alive when the screen rotates. As I understand it, the only class that lives longer than fragment/activity is Application. I have to create components for these presenters in the application, when they are not needed, I have to make them null myself. How correct is this and what are the options for where and how to create such components?
  2. I have @Scope for 3 fragments. When I go to the first fragment of this @Scope I create a component, but how do I access it from the other two fragments? If @Scope is supposed to survive the screen rotation too, then should it be in the Application class?

Source: Android Questions

Categorized as android, android-mvp, dagger-2, mvp


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us