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

After restarting the activity from the stack, presenters of its fragments are created earlier than the presenter of the activity itself #197

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Anrimian
Copy link

@Anrimian Anrimian commented Apr 28, 2018

How did I come to this:

There is activity, there are many nested fragments in it. Activity has a presenter, each fragment also has a presenter. Activity launch another activity that falls (why - it does not matter in this matter). After crashing, the system recreates the activity stack and starts the previous activity with a bunch of fragments.

However, the activity has the starting data, which lies in the intent. Passing these data to fragments through arguments is long and painful (there are a lot of them, they are nested in each other) - so I pass them through di (I use dagger2). The presenter of the activity is in the component, the presenters of the fragments are in the subcomponents of the activity component. And under this order of creation, the subcomponent tries to create before its parent component, as a result, everything flies to hell.

This answer explains the behavior, there is no turning of the device, because the presenters are not created when turning, but the situation is similar.

Yes, of course, the application should work stably and without crashes. However, in this situation, I get crash from moxy in analytics(fabric), and I do not see the root causes of crashes(maybe problem in analytics, i don't know). It is also possible that there are other ways to get this behavior.

How I solved the problem:

I created my own MvpActivity, where I called getMvpDelegate().onCreate() before calling super.onCreate(savedInstanceState).

I think this behavior should be in the library by default.

@senneco
Copy link
Collaborator

senneco commented Aug 8, 2018

Hi, @Anrimian

Sorry for my delay =)

I think that there may be some navigation problems if users change navigation stack from presenter. And than it will change fragments back stack before activity recreate this state. And there may be some problems.

I think your should make your data layer more flexible and restore them without depends on some activity or other lifecycle components. Did you?

@Anrimian
Copy link
Author

Anrimian commented Aug 9, 2018

I did not use the fragments backstack here. It is just activity with very heavy ui. And i describe very-very rarely case(restore activity after crash, this normally never happens), usually everything works fine. But it is weird, when in this case fragments presenters creates before activity presenter.

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

Successfully merging this pull request may close these issues.

2 participants