After restarting the activity from the stack, presenters of its fragments are created earlier than the presenter of the activity itself#197
Open
Anrimian wants to merge 1 commit intoArello-Mobile:developfrom
Conversation
Collaborator
|
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? |
Author
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.