0

Is there a way to run Cordova code without the app being in the foreground? I know it's possible in Flutter and React-Native, but it seems that in Cordova it's impossible.

I tried to have my Cordova application wake up in the background, in response to a silent push message. Instead it kept popping to the foreground.

1 Answer 1

1

You need to use a background task. Check out https://github.com/katzer/cordova-plugin-background-mode

6
  • Thanks, Eric. Unfortunately, it doesn't get the job done, since the deviceready event (which the plugin relies on) is fired only when the app is launched.
    – shy alon
    Commented Jun 7, 2023 at 11:32
  • You don't get it. You setup your tasks the first time the app runs. Then when your app goes to background, they run.
    – Eric
    Commented Jun 7, 2023 at 11:38
  • This will only works after the app first opens, and then it starts an Android foreground service that keeps it alive. It wont be able to call javascript in case app wakes app in background like from BootComplete event. Commented Jun 7, 2023 at 12:06
  • Then add github.com/ToniKorin/cordova-plugin-autostart
    – Eric
    Commented Jun 7, 2023 at 12:34
  • Thanks @Eric, I've look the autostart package as well. All it does is just to start some Android activity in background(BTW this is forbidden in latest Android versions) or Service on boot complete. What we want is that on BootComplete to call app javascript callback function (in cordova side) directly from the native side. Commented Jun 7, 2023 at 13:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.