fix(android): prevent error while opening modal from background #10570
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.
It is a known android "issue" that you cant commit/show a fragment while in background. The reason is, as explained here or here, that
onSaveInstanceState
is already called so any operation before activity start would be with state loss. There are 2 solutions in this case:commitAllowingStateLoss
,dismissAllowingStateLoss
... but then you loose state ... This is what we are doing in N in many cases. We can do this withshow
too but we would need to override theDialogFragment.show
method.This PR uses the second solution. We could add an option to
showModal
to use the first solution. The user experience is different. Solution 1: when the app is resumed the modal is already shown and layed out. Solution 2: you see the modal opening on app resumeEDIT: i actually implemented the 2 cases in my fork. Even though i can force
commitAllowingStateLoss
successfully from background it does not make the dialog fragment actually show while in background. I still see the open animation while putting the app back to foregroundPR Checklist
What is the current behavior?
What is the new behavior?
Fixes/Implements/Closes #[Issue Number].