question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Background Mode is running for only few(probably 5 mins) minutes in Android 8 and Android 9

See original GitHub issue

The App is running for almost 5 minutes at the background. After that, it stops working. If I resume then it starts again.

I have tried several solutions. I have also used the plugin https://github.com/DavidBriglio/cordova-plugin-foreground-service and added cordova.plugins.foregroundService.start('GPS Running', 'Background Service', 'myicon', 3, 10); cordova.plugins.backgroundMode.disableBatteryOptimizations(); cordova.plugins.backgroundMode.disableWebViewOptimizations();

But it did not work. I also tried with Cordova power management. This is my GitHub repo https://github.com/ahsanhabib23/testBackgroundIonic3 where the issue has been reproduced.

I am using the fork version. Most added the library by running this command cordova plugin add https://github.com/katzer/cordova-plugin-background-mode --nofetch

I know there is an existing open issue. But still posting because comments from there did not help.

Ionic:

   ionic (Ionic CLI)  : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.5
   @ionic/app-scripts : 3.2.2

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 6 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/bs236/Library/Android/sdk/)
   ios-deploy        : 1.9.2
   NodeJS            : v10.15.3 (/usr/local/bin/node)
   npm               : 6.9.0
   OS                : macOS High Sierra
   Xcode             : Xcode 10.1 Build version 10B61

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:33

github_iconTop GitHub Comments

6reactions
megadrazzcommented, Jul 27, 2019

Solução crie uma service com uma notificação passos!!! index.js >> receivedEvent, onDeviceReady

antes cordova.plugins.backgroundMode.setDefaults({ title: “title”, text: “text”, icon: ‘icon’, // this will look for icon.png in platforms/android/res/drawable|mipmap color: “6E10A0”, // hex format like ‘F14F4D’ resume: false, silent: false, hidden: false, bigText: false, })

       >>> aqui    cordova.plugins.backgroundMode.enable();
      >>> antes   cordova.plugins.backgroundMode.onactivate = function () {
                    cordova.plugins.backgroundMode.disableWebViewOptimizations();
                };
                cordova.plugins.backgroundMode.ondeactivate = function () {
                    alert('teste')
                };
    >>>> aqui      cordova.plugins.backgroundMode.disableBatteryOptimizations();

plugin.mxl add permission

<config-file target="AndroidManifest.xml" parent="/manifest"> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> </config-file>

inicie o service com uma notificação pegue parte do codigo plugin powemanger e inclua em seu service ele vai trabalha para servir cordova.plugins.backgroundMode para manter ele sempre ativo! abraços!!! testado Android 8 e Android 9 rodando aqui 24hs por dias! vlw

3reactions
TDolacommented, Aug 15, 2019

Do you still have the issue if you use this plugin? https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent apps from 'sleeping' in the background on ...
Start the Settings app and tap Battery & device care. Then tap Battery. On the Battery page, head to Background usage limits. Here,...
Read more >
App Standby Buckets - Android Developers
On Android 9 (API level 28) and higher, when the user interacts with your app in certain ways, the system temporarily places your...
Read more >
Android: keep Service running when app is killed
The startService() will not work as intended in and above Android Oreo 8.1, as strict background policies will soon terminate the service after...
Read more >
Android Notifications Not Showing Up? 10 Fixes You Can Try
To do that, you'll need to reboot your phone. Doing so puts an end to all background processes or services that might interfere...
Read more >
Why Is My Phone Hot? What Causes Overheating and How to ...
5 Reasons Your Phone is Overheating and How to Stop It ... leaving it in direct sunlight or malware (Androids only). ... Running...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found