cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

Dead background mode on open another app - Android 10

Open elduglas opened this issue 5 years ago • 8 comments

Hi. I'm sorry for my bad english.

Dead background mode on open another app, for example. If my APP is on Background Mode this show the notification that now is on background mode, but if I open another app that isn't on background mode for example Whatsapp or Slack, my app automatically closes.

Steps:

  1. Pass your app to background mode.
  2. Check that your app is on background mode.
  3. Open another App that isn't on background mode. (anyone)
  4. Check if your App still on background mode.

elduglas avatar Aug 08 '20 17:08 elduglas

Dead background mode on open another app - Android 10

HamidDarash avatar Aug 13 '20 06:08 HamidDarash

Could you try: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/

danielehrhardt avatar Sep 15 '20 14:09 danielehrhardt

Could you try: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/

Hi @danielehrhardt doesn't work Screen Shot 2020-09-16 at 10 43 21 AM

This is my code.

is a button method.

backgroundModeAPP(){

//if backgroundMode not active, enable it!
if (!this.backgroundMode.isActive()) {
  this.backgroundMode.enable();
  console.log("backgroundMode was enabled")
}

// if there is a failure on backgroundMode print an error
this.backgroundMode.on('failure').subscribe((err) => {
  console.error("BackgroundMode failure: " + err);
});

//Android allows to programmatically move from foreground to background or vice versa.

this.backgroundMode.moveToBackground();


//Override the back button on Android to go to background instead of closing the app.
this.backgroundMode.overrideBackButton();

//Exclude the app from the recent task list works on Android 5.0+.
this.backgroundMode.excludeFromTaskList();

// Notification settings
this.backgroundMode.setDefaults({
  title: 'Estamos en segundo plano',
  text: 'Recuerda estar disponible para recibir domicilios',
  icon: 'ic_launcher',
  resume: true,
  hidden: false,
  bigText: true
})

//background logic
this.backgroundMode.on('activate').subscribe(() => {
  this.backgroundMode.configure({
    text: 'Recuerda estar disponible para recibir domicilios'
  });
  
  this.backgroundMode.disableWebViewOptimizations();
  this.backgroundMode.disableBatteryOptimizations();      
})

}

elduglas avatar Sep 16 '20 15:09 elduglas

I have That Same Problem.How Can I Solve This Problem

dogukaniyidogan avatar Jan 28 '21 07:01 dogukaniyidogan

@dogu58 bir çözüm bulabildin mi ?

demirkolemre avatar Mar 03 '21 19:03 demirkolemre

@dogu58 bir çözüm bulabildin mi ?

no

elduglas avatar Mar 03 '21 19:03 elduglas

Hi, I have the same problem in Android 10. When "excludeFromTaskList" is active and running in background, the application closes when the user opens any other application.

I have reviewed the code and found that the "onDestroy" event is called when the user opens another app. If I change some code on "onDestroy", the problems seem to go away.

This is my modified "BackgroundMode.java" code, adding a validation of "inBackground" on the "onDestroy" event. Clearly is not a good solution, maybe a clue.

    @Override
    public void onDestroy()
    {
        if (inBackground) return; //My fix
        stopService();
        android.os.Process.killProcess(android.os.Process.myPid());
    }

binatrix avatar Apr 28 '21 16:04 binatrix

Hi, I have the same problem in Android 10. When "excludeFromTaskList" is active and running in background, the application closes when the user opens any other application.

I have reviewed the code and found that the "onDestroy" event is called when the user opens another app. If I change some code on "onDestroy", the problems seem to go away.

This is my modified "BackgroundMode.java" code, adding a validation of "inBackground" on the "onDestroy" event. Clearly is not a good solution, maybe a clue.

    @Override
    public void onDestroy()
    {
        if (inBackground) return; //My fix
        stopService();
        android.os.Process.killProcess(android.os.Process.myPid());
    }

Thank you but not work for me

can you share example code :(

demirkolemre avatar Apr 29 '21 21:04 demirkolemre