katzer / cordova-plugin-background-mode

Keep app running in background
Apache License 2.0
1.38k stars 1.02k forks source link

Application automatically goes to foreground #449

Open mstrop opened 5 years ago

mstrop commented 5 years ago

I just installed the latest version of the plugin as I had issue with running on background for longer time. It works perfect now. Unfortunately I experience new issue - when I switch to another application, my application goes automatically to foreground after couple of seconds. Repeating switching to another application helps, but the user experience is terrible. I experience this on Android 8 and 9 ( I haven't tested another one ). Plugin initiation is:

cordova.plugins.backgroundMode.onactivate = function() {
    cordova.plugins.backgroundMode.disableWebViewOptimizations();
    cordova.plugins.backgroundMode.disableBatteryOptimizations();           
};

cordova.plugins.backgroundMode.ondeactivate = function() {};        
cordova.plugins.backgroundMode.onfailure = function(errorCode) {};

cordova.plugins.backgroundMode.setDefaults({
    title: "My title",
    text: ""My text,
    icon: 'icon'
});

cordova.plugins.backgroundMode.enable();
SanjanaTailor commented 5 years ago

@mstrop: Are you not facing the same issue https://forum.ionicframework.com/t/backgroundmode-not-installing-cordova-9/160226/5 ?

mstrop commented 5 years ago

@mstrop: Are you not facing the same issue https://forum.ionicframework.com/t/backgroundmode-not-installing-cordova-9/160226/5 ?

No, my issue has nothing to do with the installation. The plugin is installed and it's working as expected. The issue is, that when my application starts running on background, it goes unexpectedly to foreground after couple of seconds.

I use Cordova 8.1.2

SanjanaTailor commented 5 years ago

Okay thank you @mstrop

silencio commented 5 years ago

I had the same issue. Adding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission solved it.

The problem (I think) is that disableBatteryOptimizations() needs this permission whereas it is not specified in plugin.xml.

You can still add it by yourself in your config.xml:

<platform name="android">
  <config-file target="AndroidManifest.xml" parent="/manifest">
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
  </config-file>
</platform>
kapilSoni101 commented 5 years ago

@mstrop : are you fixed above issue?

mstrop commented 5 years ago

@mstrop : are you fixed above issue?

I have moved to another plugin in mean time. Sorry, I haven't closed the issue.

kapilSoni101 commented 5 years ago

@mstrop : which plugin u have used sir?

mstrop commented 5 years ago

https://github.com/transistorsoft/cordova-background-geolocation-lt

sirthun commented 4 years ago

https://github.com/transistorsoft/cordova-background-geolocation-lt

this plugin have to pay or free sir?