Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presenter lifecycle tied to Activity's #30

Closed
cxzhang2 opened this issue Apr 14, 2016 · 4 comments
Closed

Presenter lifecycle tied to Activity's #30

cxzhang2 opened this issue Apr 14, 2016 · 4 comments

Comments

@cxzhang2
Copy link

Hi guys,

It looks to me as though the presenters' lifecycles are coupled to their instantiating activity's. Please let me know if I missed something, and whether or not this is a conscious design choice.

Thank you!

@IgorGanapolsky
Copy link
Contributor

@cxzhang2 What is your other proposal? Presenters need to be notified during activity lifecycle changes...

@cxzhang2
Copy link
Author

cxzhang2 commented Apr 15, 2016

@IgorGanapolsky

Sorry, clarification:

As you said, presenters should be notified of activity / fragment lifecycle events, but they should also survive configuration change.

I have seen so far two general approaches to this problem (there are also external libraries that are explicitly for this purpose but I'm not too familiar with them):

  1. With a custom singleton to hold and manage presenters. This example uses an actual singleton, and this example uses the NonConfigurationInstance of an activity.
  2. With dagger @subcomponents, as illustrated here

As far as I can tell, the presenters in this project are destroyed and re-instantiated on configuration change. Just wondering if I'm missing something or maybe this is a special case where such considerations do not apply.

Thanks!

@kboyarshinov
Copy link
Contributor

@cxzhang2 Yes, presenters are re-instantiated on every configuration change. There was no purpose to make them survive it initially. You can expose onSaveState and onRestoreState callbacks to save presenters state if you want.
Btw second example you mentioned with dagger subcomponents re-instantiates presenter too. Each time subcomponent is build QualityMattersApp.get(getContext()).applicationComponent().plus(new ItemsFragmentModule()).inject(this) new presenter is injected in fragment.

@cxzhang2
Copy link
Author

cxzhang2 commented Apr 15, 2016

Thank you @kboyarshinov , and yes you are right about the second example. I originally thought that Instances of parent components held references to instances of subcomponents. Thinking about this now it makes no sense in terms of scoping. Doh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants