Why are presenters injected to activities and not to fragments?
See original GitHub issueIs there any benefit of injecting the presenters in Activities rather than in Fragments? The Activities do nothing but attach the Fragment which handles all the user interactions using the Presenter.
Take AddEditTaskActivity
as an example. As the presenter is injected in it’s onCreate()
method, the presenter will be recreated during orientation changes. However if the presenter was injected into the AddEditTaskFragment
it would have been retained through orientation changes too. This can be particularly useful in case the presenter has to maintain any state.
Just want to know what everyone thinks about this approach?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:7 (2 by maintainers)
Top Results From Across the Web
[todo-mvp-dagger] why presenters are injected into activity ...
Currently, the approach to inject the presenter for a fragment into the hosting activity only works if the activity hosts a single fragment....
Read more >Testing Dagger-injected Fragments and Activities - Medium
The test would inject a fake presenter and check how activity interacts with it. But now we have a problem: how to inject...
Read more >Android MVP with Dagger 2 - Activity with multiple fragments
Fragments are not coupled to Activity and to other Fragments by the component itself (and the objects the component could cache if you...
Read more >Attach your presenters to view layer - ProAndroidDev
Your view can have several presenters, there can be one presenter in one fragment, or several presenters in one activity.
Read more >Presenters don't need lifecycle events - Hannes Dorfmann
Actually, this is one of the arguments why some developers are advocating against fragments (complex lifecycle) and prefer “custom views” (i.e. ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JoseAlcerreca How can we use the same presenter on 2 fragments within the same activity? Don’t you think we should have a sample of that since I think most devs use multiple fragments in the same activity.
I use it in Fragment. But I find Presenter will be NULL when I recycle my memory.