gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:53:23 27 4
gpt4 key购买 nike

我有一个 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()

关于android - 如何在 Android 上优雅地关闭 kivy 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42876693/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com