Fix crash on double rotation with modal #1288
Closed
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.
Fixes wordpress-mobile/WordPress-Android#10227
WIP - Do Not Merge Yet
Related PRs
WordPress-Android: wordpress-mobile/WordPress-Android#10383
Description
Since
GutenbergContainerFragmentis retained, it lives outside of the activity lifecycle. This results in a change in the way the fragment lifecycle methods are called with respect to the activity lifecylcle. Specifically,onDestroyis not called when an activity is re-created.The
GutenbergContainerFragmentinstantiates and keeps a reference to aWPAndroidGlueCode, which, in turn, instantiates and keeps a reference to aReactInstanceManager, all of which live outside the activity lifecycle. When the fragment is destroyed, theReactInstanceManager'sonHostDestroymethod is called with the current activity, to perform cleanup. However, this does not occur when the fragment is retained, as it is only called through from the fragment'sonDestroymethod.This PR overrides the fragment's
onDetachmethod, calling through to a newonDetachmethod on the WPAndroidGlueCode. That method performs the cleanup with the activity being destroyed (e.g. during an orientation change).This approach works, but I think the current state could be cleaned up, thus, this PR is only a draft, with the intent to gather more context. It may be that we can simplify this to changing the fragment to directly call
WPAndroidGlueCode'sonDestroymethod, rather than creating the method of the same name there.To test:
Follow steps here: wordpress-mobile/WordPress-Android#10227 (comment) and here: wordpress-mobile/WordPress-Android#10227 (comment)
Update release notes:
RELEASE-NOTES.txt.