Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(android): prevent possible crash when app goes to background #9347

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

Merged

Conversation

farfromrefug
Copy link
Collaborator

We faced the same issue with the material components. The old N team knew about it and try to prevent it by testing the fragment manager. However that test is not enough and we can see that we still go into onAttachedWindow after onStop while putting the app to background.
This new check ensure we dont go there in that case.
It might solve some reported issues not sure.

# Conflicts:
#	packages/core/ui/frame/index.android.ts
@cla-bot cla-bot bot added the cla: yes label Apr 20, 2021
if (this._manager && this._manager.isDestroyed()) {
// still happens with androidx.fragment:1.3.2
const activity = androidApplication.foregroundActivity;
if ((this._manager && this._manager.isDestroyed()) || !activity.getLifecycle().getCurrentState().isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it’s possible that getLifecycle() or getCurrentState() could ever return null under some unexpected conditions? Might be safest to just guard those calls as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should not and I would prefer to not have the code let you believe they can.
androidx appcompatacticity have a life cycle and getCurrentState returns an enum

@NathanWalker NathanWalker added this to the 8.1 milestone Jul 12, 2021
@NathanWalker NathanWalker changed the base branch from master to release/8.1.0 August 11, 2021 18:38
@NathanWalker NathanWalker merged commit 47df889 into NativeScript:release/8.1.0 Aug 11, 2021
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