Background timer stops after a while when the phone is locked [Android]
See original GitHub issueThis is the example of the code
var time = 0;
BackgroundTimer.setInterval(() => {
time ++;
console.log(time)
}, 1000)
Let say in my log it shows
...
331
332
333
...
Then the timer stop here When I unlocked my phone again and open the app again
...
331
332
333
334
335
336
337
...
The variable of time suddenly increase many times. It seems like the adding process stack and run at once. This happened when I test the app on my device without USB connection. However with USB connection, the problem resolved (most likely is because it is charged when connected with USB ) The phone model is Google Pixel 1 and Android version is 9. The battery optimization is disabled already. Does anybody have this issue as well?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:11
Top Results From Across the Web
[Android] Stop working when phone is locked #15 - GitHub
But when app has been installed by .apk file then timer is stopped after 30-40 seconds (when phone is locked).
Read more >React-native-background timer stop working after 15 minutes ...
Android automatically kills your app after a certain time of inactivity so you cannot run a endless process in background.
Read more >Tracks stop playing after my Android device goes to sleep mode.
Launch Android settings; Select Wireless and Networks; Select Data Usage; Tap the 3DOTS on the top right; Tap 'Restrict Background Data' and disable...
Read more >Interval timer stops working when screen locks. - WEBcazine
Im using an interval timer when working out. Basically i need a beep every 60 seconds. When lock screen comes on, it stops...
Read more >Is it possible the timer works when phone locked? - MSDN
Timers.Timer in core layer, cuz I'm going to make an android ... to keep it working when device locked or application in background??...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same here. Android 9, samsung a20. Timer stop after 15min the app is in background. It resumes after unlocking the phone just like you said.
Hi, I had this same issue and found no easy solution with this library, so I made my own which works even if the device is locked (among other improvements). Only Android is supported, but you can still use this (or another) library for iOS in conjunction.
https://www.npmjs.com/package/react-native-background-timer-android
I’ve been using it in my production apps for more than a week with no issues.