I\'m trying to build an android APP with kivy,my requirement is quit simple:
When open the android APP,it will start counting from 0, and a prompt will pop up in the stat
is this code
from jnius import autoclass
service = autoclass(SERVICE_NAME)
mActivity = autoclass(u'org.kivy.android.PythonActivity').mActivity
argument = ''
service.start(mActivity, argument)
inside the service.py or main.py
After days test,I solved the problem
My previous understanding of background operation is indeed problematic, or my solution is just one of the ways to achieve goal.
in main.py,define the service name,e.g.
SERVICE_NAME = u'{packagename}.Service{servicename}'.format(
packagename=u'org.kivy.test',
servicename=u'Myservice'
)
and in the place need to start service,
from jnius import autoclass
service = autoclass(SERVICE_NAME)
mActivity = autoclass(u'org.kivy.android.PythonActivity').mActivity
argument = ''
service.start(mActivity, argument)
in buildozer.spec,
# (str) Package name
package.name = test
# (str) Package domain (needed for android/ios packaging)
package.domain = org.kivy
# (list) List of service to declare
services = Myservice:service.py
and then,edit the service.py as needed,the main.py and service.py can be communicated by oscpy
By doing above,The notification can be popped up after open APP,even the APP is switched to background