After restarting the activity from the stack, presenters of its fragments are created earlier than the presenter of the activity itself #197
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.