[英]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.