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

iOS: ON_NEXT_SUSPEND - cancel the timer in applicationDidBecomeActive method #1991

Merged

Conversation

atrutnev
Copy link
Contributor

@atrutnev atrutnev commented Dec 1, 2020

When the application goes to background and then returns back (for example, when user presses Home button and then open the application again), it goes through the following methods:
applicationWillResignActive -> applicationDidEnterBackground ->  applicationWillEnterForeground -> applicationDidBecomeActive

In case of minimization on the screen, using App switcher or temporary interruptions and then the application returns back, it goes through the following methods:
applicationWillResignActive -> applicationDidBecomeActive

The explanation of the methods can be found here - https://developer.apple.com/documentation/uikit/uiapplicationdelegate?language=objc

The current logic starts the minimumBackgroundDuration timer in applicationWillResignActive but the timer is being cancelled in applicationWillEnterForeground method. Looks like it's a cause of application auto restart after temporary interruptions like push notifications.

I would suggest to cancel that timer in applicationDidBecomeActive method instead of applicationWillEnterForeground to avoid the unexpected restart; applicationDidBecomeActive will be called in all cases when the application is going to be active. Also it doesn't change anything in case of usage ON_NEXT_RESUME option.

Looks like the issue doesn't appear on Android due to differences in application life cycle.

#1911

@ghost
Copy link

ghost commented Dec 1, 2020

CLA assistant check
All CLA requirements met.

@atrutnev atrutnev merged commit b15a019 into microsoft:master Dec 7, 2020
@atrutnev atrutnev deleted the dev/v-altrut/ios-restart-on-next-suspend branch December 7, 2020 14:12
sourabhdebnath pushed a commit to scripbox/react-native-code-push that referenced this pull request May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants