question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why are presenters injected to activities and not to fragments?

See original GitHub issue

Is 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:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
ac-opensourcecommented, Jul 3, 2016

@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.

3reactions
jjzhoujuncommented, Jun 30, 2016

I use it in Fragment. But I find Presenter will be NULL when I recycle my memory.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found