Content-Length: 247693 | pFad | https://github.com/NativeScript/NativeScript/pull/10570

E5 fix(android): prevent error while opening modal from background by farfromrefug · Pull Request #10570 · NativeScript/NativeScript · GitHub
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

fix(android): prevent error while opening modal from background #10570

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

farfromrefug
Copy link
Collaborator

@farfromrefug farfromrefug commented Jul 3, 2024

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:

  • use commitAllowingStateLoss, dismissAllowingStateLoss ... but then you loose state ... This is what we are doing in N in many cases. We can do this with show too but we would need to override the DialogFragment.show method.
  • delay the action until the activity is resumed.

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 resume

EDIT: 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 foreground

PR Checklist

What is the current behavior?

What is the new behavior?

Fixes/Implements/Closes #[Issue Number].

It is a known android "issue" that you cant commit/show a fragment while in background. The reason is, as explained [here](https://medium.com/@113408/avoid-fragment-illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-ba76ae4f00fe) or [here](https://stackoverflow.com/questions/15729138/on-showing-dialog-i-get-can-not-perform-this-action-after-onsaveinstancestate), that `onSaveInstanceState` is already called so any operation before activity start would be with state loss.
There are 2 solutions in this case:
* use `commitAllowingStateLoss`, `dismissAllowingStateLoss` ... but then you loose state ... This is what we are doing in N in many cases. We can do this with `show` too but we would need to override the `DialogFragment.show` method.
* delay the action until the activity is resumed.

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 resume
@cla-bot cla-bot bot added the cla: yes label Jul 3, 2024
@NathanWalker NathanWalker added this to the 8.8 milestone Jul 3, 2024
@NathanWalker NathanWalker merged commit 7e9be32 into main Jul 3, 2024
4 checks passed
@NathanWalker NathanWalker deleted the farfromrefug-patch-1 branch July 3, 2024 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/NativeScript/NativeScript/pull/10570

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy