-
Notifications
You must be signed in to change notification settings - Fork 1k
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
SetInterval/SetTimeout stops working after 5 mins #518
Comments
Does this help me to prevent notifications from freezing after 10 minutes? My application shows the name of the song with the cover but when it is in the background the information in the notification bar stops updating after 10 minutes and freezes and does not refresh until the application is opened. |
I have made exactly the same test with a setInterval and I have the same problem. Do you have solved it? |
I needed to call |
I tried it, it works, disableWebViewOptimizations call webview’s onShow method, so it must be called in pause event |
function manageEvents() { function onDeviceReady() { function onPause() { Doesn’t even work by inserting disableWebViewOptimizations() in Cordova's pause event. |
@riccardocostantini I've been using this version instead: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/ The exact code that works for me is:
Note, there's still an Android power optimization (doze mode) that kicks in after 40mins-1hr which will throttle this even then. Additionally, if your app uses too much CPU, you might be throttled by Android. Are you seeing the exact issue here where the interval stops after 5mins? |
@peitschie I've been using this version: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/ and i reproduced your code but after 5 minutes set interval stops working. |
@peitschie any news? |
I have no obvious answers sorry @riccardocostantini Not sure if there's something different about your environment to my own test setup to cause this, but this kind of power thing is very difficult to guess. |
What version of java are you using? @peitschie |
Can you try this version? |
No, i try this https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/ or this https://github.com/katzer/cordova-plugin-background-mode. |
@riccardocostantini No, but my app is working fine.. did you declare the service type on xml? https://developer.android.com/about/versions/14/changes/fgs-types-required |
@bonanhel |
@riccardocostantini Yes, on Android 10+ you must declare the foreground service type. For example GPS, Media etc.. Yes, all my timers are working fine on background (Using foreground service) |
Thanks for the answer @bonanhel. document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { But after 5 minutes setInterval stop working in background. Do you have any suggestions? |
You need to declare the foreground service for the plugin within the element. You'll find a line like this:
However, you must declare it like this:
camera On js
|
@bonanhel thanks for the response. But I not view in your comment this line: |
@riccardocostantini Sorry for the confusion earlier, it seems there was an issue with the code formatting in the GitHub editor. Could you please take another look? |
@bonanhel |
@bonanhel
this error occurred:
|
@riccardocostantini Yes, plugin also added this line . make a code search on plugins directory for this line and update it there. Then don’t add it on xml and let plugin to append it |
@bonanhel My androidmanifest: my js:
First console.log on chrome inspect device: 12:39:41.407 OK |
@bonanhel any news? |
@riccardocostantini Sorry, can’t help. It works here. I guess you need to check further your Android app configuration. |
@bonanhel thanks for response. What kind of configuration are you talking about? |
@bonanhel with your directives, the problem arises when I go to kill the app, because when I normally close the app from the home button, it works properly. |
@riccardocostantini killing the app is something done by Android. There's no protection or recovery guaranteed from this action by the user. See for models and details: https://dontkillmyapp.com/ |
@peitschie the method onDestroy() cause the process ended. |
I have a requirement of a timer, that should send out notification (I am used onesignal API notification) after a particular user set value is reached.
For example if a user sets a value of 7 mins, the timer should send notification after 7 mins. The time a user can set varies from 1-59 mins. But even with using the background mode plugin, I cannot get the setInterval/setTimeout functions to work after 5 mins.
Tried using recursive setTimeout method:
Tried using the setInterval method:
The background activation notification at the top and I can see that the background mode is active. But the timer doesn't seem to be running after 5 mins.
any idea how this could be solved?
The text was updated successfully, but these errors were encountered: