katzer / cordova-plugin-background-mode

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

I did my own fork to fix moveToBackground on Android #576

Open alindzon opened 1 year ago

alindzon commented 1 year ago

The way it is written it goes to the home screen. I wanted to go back to whatever the previous foreground app was. Took hours but I found it. I recommend whomever is maintaining this plugin to adopt this code instead.

private void moveToBackground() { Activity app = getApp(); app.moveTaskToBack(true); }

alindzon commented 1 year ago

I also had to fix a bug in recent Android releases. for pendingintents you need to have a FLAG_MUTABLE or the opposite. So I had to edit ForeGroundService.java adding | PendingIntet.FLAG_MUTABLE as shown below on line 225.

if (intent != null && settings.optBoolean("resume")) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity( context, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);