1

If the following is how you start an android service with Kivy, how do you stop a service from the front end? I already know how to make the service stop itself in the service, i want to stop it from the frontend:

from android import AndroidService
service = AndroidService('myApp', 'status: active')
service.start('service started')
self.service = service

I tried the following but it does not work:

from jnius import autoclass
service = autoclass('org.renpy.android.PythonService').mService
service.stopService()
Jeff
  • 551
  • 1
  • 5
  • 19

1 Answers1

1

If you use python-for-android's newer services api, which I recommend, you can manage the service via pyjnius as follows:

        from jnius import autoclass
        service = autoclass('your.service.name.ClassName')
        mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
        service.stop(mActivity)

If using the old way with the android module (which isn't that well supported right now), it looks like you should be able to call service.stop() on your AndroidService object.

inclement
  • 29,124
  • 4
  • 48
  • 60
  • Hi @incement what do you mean by this line: `service = autoclass('your.service.name.ClassName')` what is the `ClassName`. Do you mind typing it out as any random example? – Jeff Sep 16 '17 at 12:46
  • Sorry, I forgot to link to http://python-for-android.readthedocs.io/en/latest/services/#arbitrary-service-scripts, which explains how the service name is set. – inclement Sep 16 '17 at 15:53