Red-Folder / bgs-core

Core code for the Cordova Background Service
Other
236 stars 105 forks source link

Backgound service stops when the app is terminated #101

Closed sahidk closed 5 years ago

sahidk commented 5 years ago

I'm trying to use this plugin to make the service running even after the app is closed or cleared from recent list. But the service is also getting terminated when the app is closed. Is that the desired behavior? I was under the impression that using this plugin I can keep my app running even after it is closed, something like WhatsApp. Please clarify.

BTW, I'm trying with cordova 8 and android 27 emulator.

Red-Folder commented 5 years ago

Yes that was the intention - when it was written originally back in 2013

This was however before various changes in Android and how it handles background services (including the kill on swipe). The Android team have actively worked to improve the user experience and battery life - however, in doing the right thing, they have made it quick difficult to have an "always running" service.

As I say, the Android team was correct to do this because there where a lot of apps "always running" for poor reasons and having very negative affect on the user experience.

Since then, the Android team have provided various better methods for what developers previously used "always running" services for - such as running services in the foreground (https://developer.android.com/guide/components/services#Foreground) and Job Scheduler (https://developer.android.com/topic/performance/scheduling).

All good stuff ... but this plugin hasn't been updated to reflect those changes. Its a fairly basic implementation of the background service - it certainly isn't bullet proof to be "always running".

And it is unlikely to ever be - I can't see myself investing the tens (if not hundreds) of hours to do that.

sahidk commented 5 years ago

Thank you so much for clarifying. I'll explore the alternatives.