Do not stop service if task removed : #1783
Comment the stopSelf(); in onTaskRemoved.
Thanks @brvier for the pull request. Could you elaborate why this is needed? This was introduced in https://github.com/kivy/python-for-android/pull/1374 for a specific reason described in the PR and in the method comment. Why do you think it's not needed? Also why just commenting it rather than deleting? Last if we end up adopting that change (still have to test it), we also want to update the method documentation
Why commenting it ? Bad habits.
I don't understand why you want killing service and testing it when app is closed.
One example, if you have a Bluetooth connection in your service, you lost it, need to rescan, which could not be done at any moment in a background service, especially on some devices which prevent Bluetooth scan in background.
All other background service do the same. I'll found other example and try to understand why this was introduced in #1374
Stopping the service explicitly was a workaround to have it start again automatically when the app is killed actually. This is working in conjonction of setAutoRestartService() introduced in https://github.com/kivy/python-for-android/pull/643 and https://github.com/kivy/python-for-android/pull/1374
I don't understand why you want killing service and testing it when app is closed.
From my own tests if the system kills the app at any point to preserve battery the service will actually continue to run. From this it appears that this service stop only happens if the user explicitly stops the app either via some integrated button calling sys.exit() (if you add any), or via recent apps wipe to get rid of it. The main purpose of a service to survive Android's auto-cleanup and keep vital functionality running appears to be preserved.
And isn't it kind of expected that everything stops when the user shuts down the app explicitly? Can you elaborate why you would want to not have that happen?
And isn't it kind of expected that everything stops when the user shuts down the app explicitly? Can you elaborate why you would want to not have that happen?
Not exactly, you should close user interface, but you should also keep background service communicating with external device working. There are many example of service running in background while user kill the app but it s mandatory to keep a permanent notification :
- Audio Apps : AntennaPods (A podcast player), Spotify
- Event based apps : KDE Connect, Syncthings, IFTTT
- App communicating with device in real time : Mi Fit (Xiaomi Mi Band), GadgetBridge (for pebble),
There are many examples :)
In our app, we are trying to have a service that runs in the background regardless of user interaction. Can we get this merged?