I'm starting a service from my Kivy app:
service = autoclass('net.saband.myapp.ServiceMyservice')
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
service.start(mActivity, '')
It works. And if I close my app using the back button my service still works. But if I close my app by swiping it out from the recent apps list the service dies.
I've found this issue and tried to use startForeground
guided by this article. It works but the notification is not removable so this solution doesn't suit me.
I've read this question and it looks like I could be helped using START_STICKY... but it's kivy service so how can I implement it? I've tried to edit Service.tmpl.java in my python-for-android templates and change this:
public class Service{{ name|capitalize }} extends PythonService {
{% if sticky %}
@Override
public int startType() {
return START_STICKY;
}
{% endif %}
...
to this:
public class Service{{ name|capitalize }} extends PythonService {
@Override
public int startType() {
return START_STICKY;
}
(Yes, I understand that {% if sticky %}
means that I can set it somewhere but in the official docs there is not a word about it.)
But nothing changed, the service still dies. According the logs the restart is scheduled:
11-17 22:52:07.140 1496 1511 I ActivityManager: Killing 29431:net.saband.myapp/u0a122 (adj 9): remove task
11-17 22:52:07.219 1496 3404 I WindowState: WIN DEATH: Window{3c605b3 u0 net.saband.myapp/org.kivy.android.PythonActivity}
11-17 22:52:07.220 1496 3404 W WindowManager: Force-removing child win Window{5ed4ff u0 SurfaceView} from container Window{3c605b3 u0 net.saband.myapp/org.kivy.android.PythonActivity}
11-17 22:52:07.225 1496 2871 W WindowManager: Failed looking up window
11-17 22:52:07.225 1496 2871 W WindowManager: java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@c7f2770 does not exist
11-17 22:52:07.225 1496 2871 W WindowManager: at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8821)
11-17 22:52:07.225 1496 2871 W WindowManager: at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8812)
11-17 22:52:07.225 1496 2871 W WindowManager: at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1212)
11-17 22:52:07.225 1496 2871 W WindowManager: at android.os.BinderProxy.sendDeathNotice(Binder.java:558)
11-17 22:52:07.225 1496 2871 I WindowState: WIN DEATH: null
11-17 22:52:07.247 1496 3311 D ActivityManager: cleanUpApplicationRecord -- 29431
11-17 22:52:07.250 1496 3538 I ActivityManager: Killing 29366:net.saband.myapp:service_myservice/u0a122 (adj 8): remove task
11-17 22:52:07.304 1496 3557 D ActivityManager: cleanUpApplicationRecord -- 29366
11-17 22:52:07.305 1496 3557 W ActivityManager: Scheduling restart of crashed service net.saband.myapp/.ServiceMyservice in 1000ms
But nothing happens.
I need the service to continue to work even when the app is closed by swiping it out from the recent apps list. And I need removable notifications. That's all. Many apps can do it. But is there a way to do it with Kivy and python-for-android?
Thanks.