Skip to content
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

Task Runner does not run at intervals #88

Closed
vycoder opened this issue May 3, 2024 · 2 comments
Closed

Task Runner does not run at intervals #88

vycoder opened this issue May 3, 2024 · 2 comments

Comments

@vycoder
Copy link

vycoder commented May 3, 2024

I tried the plugin and I was able to make it work but I can't seem to make the interval work.

I have a runner that just have:

addEventListener('keepAlive', (resolve, reject, args) => {
  console.log('--> background.runner: Keep-Alive Tick')
  resolve()
})

And my config:

...
"BackgroundRunner": {
      "label": "com.background.task",
      "src": "runners/index.js",
      "event": "keepAlive",
      "repeat": true,
      "interval": 1,
      "autoStart": true
    },
...

But it only ran once, exactly one (1) minute after it was backgrounded. But it never ran again. Did I configure things wrong?

Also, is there way to remove Geolocation permissions? I'm not exactly using them. For context, I'm trying to prevent Android from killing/pausing my app when backgrounded, I'm playing WebAudio on a setInterval indefinitely but Android (most especially Google Pixel devices) keeps pausing the app and audio.

Here's the relevant logs:

2024-05-03 20:11:26.856 11386-15389 Runner                  com.background.task         D  created runner
2024-05-03 20:11:26.871 11386-15389 Runner Con...round.task com.background.task         I  --> background.runner: Keep-Alive Tick
2024-05-03 20:11:26.871 11386-15389 Runner                  com.background.task         D  try to destroy context com.background.task
2024-05-03 20:11:26.871 11386-15389 com.background.task     com.background.task         I  Destroying context
2024-05-03 20:11:26.871 11386-15389 Runner                  com.background.task         D  destroying runner
2024-05-03 20:11:26.871 11386-15389 Runner                  com.background.task         D  freeing runtime
2024-05-03 20:11:26.872 11386-15389 Runner                  com.background.task         D  destroyed runner
2024-05-03 20:11:26.877 11386-11405 WM-WorkerWrapper        com.background.task         I  Worker result SUCCESS for Work [ id=6f984c01-ca12-4554-b0c2-a509fd84d4dd, tags={ io.ionic.backgroundrunner.plugin.RunnerWorker, com.background.task } ]
@theproducer
Copy link
Collaborator

Hello! A few things here:

On Android, jobs have a minimum interval time of 15 minutes.

Additionally, there could be battery optimization stuff that might limit how often the task runs, see here for more info.

Regarding the Geolocation issue, we are tracking that here:
#86
Im working on a way to selectively disable APIs (and their relevant permissions) that you aren't using.

For context, I'm trying to prevent Android from killing/pausing my app when backgrounded, I'm playing WebAudio on a setInterval indefinitely but Android (most especially Google Pixel devices) keeps pausing the app and audio.

Yeah, that's not going to work, and currently won't work in Background Runner. When Android kills your app when it's no longer in the foreground, the WebView containing your app code goes with it, stopping anything you are playing through WebAudio. If you intend on using the Background Runner to "keep alive" the activity so that it keeps running - that's not possible.

If you need to play audio even when the app is in the background, you may have to write a solution in native code:
https://developer.android.com/media/media3/session/background-playback

This is definitely some functionality we can expose through the Background Runner in the future.

@vycoder
Copy link
Author

vycoder commented May 5, 2024

I see, thanks for all the information! I might need to write native code after all. I was already working on moving away from web audio to native audio for a different issue and was just wondering if this plugin could be a quick fix for Pixel devices.

Anyway, I'll be closing this issue and just track the geolocation perms on #85 (I'll still probably use this plugin for caching stuff - is probably the best use for this plugin).

Thanks again!

@vycoder vycoder closed this as completed May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants