Unibozu opened a new issue #616: setInterval/setTimeout are triggered when the app is paused? URL: https://github.com/apache/cordova-android/issues/616 Hi, Kind of a support request related to an issue I've explained in https://github.com/apache/cordova-plugin-geolocation/issues/141. What I've noticed is that cordova triggers `setInterval` even when the app is paused. The issue appeared on a large application, so I've replicated it on an empty cordova project. ### POC Init a new project ```sh cordova create test-timer && cd test-timer cordova platform add android ``` Add this to a js file (or use an inline tag after removing the CSP meta) ```js document.addEventListener('pause', () => console.log('pause')); document.addEventListener('resume', () => console.log('resume')); setInterval(() => console.log('ping500'), 500); setInterval(() => console.log('ping10000'), 10000); ``` Run and debug: `cordova run --device && adb logcat -e CONSOLE` Let the app runs a bit, you'll see all the ping500 messages. Then go back to the home screen. I would expect the interval to stop but they continue running in the background - until the app is actually killed. `adb logcat -e CONSOLE` ``` 01-16 14:50:06.946 4127 4127 I chromium: [INFO:CONSOLE(42)] "Received Event: deviceready", source: file:///android_asset/www/js/index.js (42) 01-16 14:50:07.296 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:07.783 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:08.284 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:08.779 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:09.279 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:09.778 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:09.788 4127 4127 I chromium: [INFO:CONSOLE(39)] "pause", source: file:///android_asset/www/index.html (39) 01-16 14:50:10.880 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:11.881 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:12.883 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:13.882 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:14.900 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:15.894 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:16.881 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:16.888 4127 4127 I chromium: [INFO:CONSOLE(42)] "ping10000", source: file:///android_asset/www/index.html (42) 01-16 14:50:17.884 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:18.878 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:19.525 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:19.526 4127 4127 I chromium: [INFO:CONSOLE(40)] "resume", source: file:///android_asset/www/index.html (40) 01-16 14:50:19.777 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:20.278 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:20.779 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:21.277 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:21.688 4127 4127 I chromium: [INFO:CONSOLE(39)] "pause", source: file:///android_asset/www/index.html (39) 01-16 14:50:21.795 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) 01-16 14:50:22.886 4127 4127 I chromium: [INFO:CONSOLE(41)] "ping500", source: file:///android_asset/www/index.html (41) ``` I haven't pushed it any further but I'd expect the app to allow any timeout/interval to trigger when paused, which might let me send some XHR requests but the extend of possible interactions is unknown. Is this behaviour normal? there is little literatture on this topic and most people seems to agree that timers are not executing in the background. Cheers
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
