iOS: ON_NEXT_SUSPEND - cancel the timer in applicationDidBecomeActive method #1991
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.
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