Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

android - Run the application in background

I am trying to build android app using kivy. How I can hide my app but still keep it running in the background like a deamon?

from kivy.config import Config
Config.set('graphics', 'fullscreen', 'fake')

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        button = Button(text="Exit", size_hint=(None, None))
        button.bind(on_press=exit)
        return button

if __name__ == '__main__':
    MyApp().run()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to use an android service if you want to actually do computation in the background. Python-for-android can do this, the relevant documentation is here (old_toolchain). For the new toolchain method see here.

If you just want your app to not be closed completely (so that it doesn't restart entirely with the splash screen etc. every time), you just have to add an on_pause method to your App class, and it should return True. You can also do any pre-pause stuff in this method. However, the app doesn't really keep running, it just keeps memory state.

In the latter case, be aware that android can and sometimes will kill apps in a pause state. This is a normal part of the way apps are handled and you can't avoid it, so you should save any important state in your on_pause method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...