appStateChange listener failure during OS-level backgrounding
0 reputation · 29 Nov 2023, 06:06 UTC
Capacitor App Plugin Lifecycle Management
The Capacitor App plugin utilizes a bridge to dispatch appStateChange events from native Java/Kotlin or Swift environments to the JavaScript layer. This mechanism allows web applications to react when the app transitions between foreground and background states.
A critical constraint exists regarding the timing of these asynchronous events. Because the native OS may suspend the WebView process rapidly during backgrounding, there is uncertainty regarding whether the bridge can guarantee the execution of JavaScript listeners before the environment is frozen.
If the OS terminates the process or suspends the WebView before the callback is processed, essential state-saving logic may be skipped.
- Does the Capacitor bridge ensure the delivery of the
appStateChangeevent before the WebView is suspended on iOS and Android? - What is the guaranteed window of execution for JavaScript listeners once the native state change is detected?