繁体   English   中英

如何在Android上优雅地关闭一个kivy应用程序?

[英]how to close gracefully a kivy app on Android?

我有一个内容的kivy应用程序:

Button:
    text: "Close"
    on_release: app.stop()

这很好用。 但不幸的是,当应用程序在Android上执行时,应用程序停止但不优雅,因为Android对话框打开,表示应用程序已关闭。 这不是正常结局的预期行为。

所以我的问题是:如何在Android上优雅地关闭一个kivy应用程序,以便看不到这个烦人的对话框?

下面是logcat的输出:

I/python  ( 4960): ANSWERS (on_stop in App) =  None
I/python  ( 4960): screen names =  ['welcome']
I/python  ( 4960): answers have been saved on disk
I/python  ( 4960): closing the SQL connection...
I/python  ( 4960): now returning True
I/python  ( 4960): [INFO   ] [Base        ] Leaving application in progress...
I/python  ( 4960): ANSWERS (on_stop in App) =  None
I/python  ( 4960): screen names =  ['welcome']
I/python  ( 4960): answers have been saved on disk
I/python  ( 4960): closing the SQL connection...
I/python  ( 4960): now returning True
I/python  ( 4960): Python for android ended.

如您所见,App.on_stop()方法似乎已被调用两次。

谢谢你的想法。

你有没有覆盖你的应用程序的on_stop()方法? 试试这个。

from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.app import App


Builder.load_string("""
<MyWidget>:
    BoxLayout:
        Button:
            text: "Close"
            on_release: app.stop()
""")


class MyWidget(BoxLayout):
    pass


class MyApp(App):
    def build(self):
        return MyWidget()

    def on_stop(self):
        return True

if __name__ == '__main__':
    MyApp().run()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM