Android Background task

68 views
Skip to first unread message

Mohamed

unread,
Jan 15, 2018, 9:48:33 AM1/15/18
to Kivy users support
I have a python service as bot.py 

bot.py 
import time
= 0  
while (True):
      time
.sleep(1)
      i 
+= 1
      
print(i)

calling it from main.py 

if platform == 'android':
service = autoclass('org.test.myapp.ServiceBot')
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
argument = ''
service.start(mActivity, argument)

after calling the service to run I want to keep this task(ServiceBot) running after closing the app, how I can implement that?

the log output after closing the app:
01-15 14:47:32.961   890  1391 I ActivityManager: Killing 28386:org.test.myapp:service_bot/u0a166 (adj 5): remove task
01-15 14:47:33.015   890   901 D ActivityManager: SVC-handleAppDiedLocked: app = ProcessRecord{69c2e8 28386:org.test.myapp:service_bot/u0a166}, app.pid = 28386

Alexander Taylor

unread,
Jan 18, 2018, 6:55:21 PM1/18/18
to Kivy users support
From a quick search, it looks like the python-for-android service code is missing what's needed to start as a sticky foreground service that can outlast the app activity. https://stackoverflow.com/questions/42126979/cannot-keep-android-service-alive-after-app-is-closed gives some information, and these steps would need to be applied at https://github.com/kivy/python-for-android/blob/master/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonService.java .
Reply all
Reply to author
Forward
0 new messages