在后台运行的kivy应用 [英] run the application in background in kivy

查看:991
本文介绍了在后台运行的kivy应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用kivy构建Android应用程序。如何隐藏我的应用程序,但像一个守护进程在后台还在运行?

 从kivy.config导入配置
Config.set(图形,全屏,假)

从kivy.app导入应用程序
从kivy.uix.button导入按钮

类MyApp的程序(App):
    高清版本(个体经营):
        按钮=按钮(文=退出,size_hint =(无,无))
        button.bind(ON_ preSS =出口)
        返回按钮

如果__name__ =='__main__':
    MyApp的()。运行()
 

解决方案

您需要的,如果你想真正做计算在后台使用的机器人服务。 Python的换机器人可以做到这一点,相关的文档的这里

如果你只是想你的应用程序没有完全关闭(使之不与闪屏等,每次重新启动完全),你只需要添加一个 on_pause 方法,您的应用程序类,它应该返回。你也可以做任何pre-暂停东西,在这个方法中。但是,应用程序并没有真正坚持跑步,它只是让内存状态。

在后一种情况下,要知道,机器人就可以,有时会杀死暂停状态的应用程序。这是应用程序的处理方式正常的一部分,你不能避免它,所以你应该保存任何重要的国家在 on_pause 方法。

I am trying to build android app using kivy. How I can hide my app but still 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()

解决方案

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.

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.

这篇关于在后台运行的kivy应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆