After days of testing, I solved the problem
My previous understanding of background operation is indeed problematic, or my solution is just one of the ways to achieve the goal.
in main.py, define the service and start it:
from jnius import autoclass
SERVICE_NAME = u'{packagename}.Service{servicename}'.format(
packagename=u'org.kivy.test',
servicename=u'Myservice'
)
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 communicate using oscpy.
By doing the above, the notification can be popped up after open APP, even the APP is switched to the background.
Answer from KuMasann on Stack Overflowpython - How to keep kivy service running in background in Android (service still run when switch to other App or lock the screen)? - Stack Overflow
How to start service in python kivy on android in background mode? - Stack Overflow
kivy apps background service for android
see: https://github.com/Android-for-Python/Android-for-Python-Users
More on reddit.compython - Kivy android service in background and customization - Stack Overflow
After days of testing, I solved the problem
My previous understanding of background operation is indeed problematic, or my solution is just one of the ways to achieve the goal.
in main.py, define the service and start it:
from jnius import autoclass
SERVICE_NAME = u'{packagename}.Service{servicename}'.format(
packagename=u'org.kivy.test',
servicename=u'Myservice'
)
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 communicate using oscpy.
By doing the above, the notification can be popped up after open APP, even the APP is switched to the background.
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
guys if anyone knows can u pls tell how to make a kivy app run in background for android.....
waiting for ur reply.. thanks in advance !!!!
Hey all, been working on an app for a while, when getting to the final home stretch I realized the way I've been doing things has a total dealbreaker without me more or less learning an area I can't even quite find out how to scratch the surface of. In short my apps functionality depends quite largely on timers etc... letting the user know when certain times are up etc... 150 or so hours into it I made the realization that standard behavior is going to pause the app whenever the screen locks or the user switches apps. Which effectively nullifies the entire point of what I want to make. It needs to be able to either play sounds or send notifications regardless of whether the user keeps the phone awake etc...
Researching on my own, I know I need a background service, of which I can find decent documentation on how to start a service. But I constantly am finding only tiny fragments of what a service actually looks like, and I have 0 clues of how to actually send data back and forth between said service and the gui app itself etc...
For the most part I learn well by finding apps with at least some portion of what I'm doing, seeing everything in context and learning from that. When it comes to any apps that use services to do things, or send notifications back and forth, I'm pretty much hitting a desert there. Anyone know of any apps of which the code is availible that has a background service that gets data from a kivy app, and sends some forms of notification? Or any documentation that has large amounts of explanations of how to code something like that with context?
I can find quite a few links to say https://python-for-android.readthedocs.io/en/latest/services/ but that tells me very little beyond how to start a service, I don't know what a service should look like, how to pass data back and forth between that and the main program etc...