climb65
climb65

Reputation: 193

how to close gracefully a kivy app on Android?

I have a kivy app with this inside :

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

This works well. But unfortunately, when the app is executed on Android, the app stops but not gracefully as an Android dialog box opens up saying that the app has been closed. And this is not the expected behavior of a normal ending.

So my question : how to close gracefully a kivy app on Android in order to not see this annoying dialog box?

Below is the output of 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.

As you can see, the App.on_stop() method seems to have been called twice.

Thanks for your ideas.

Upvotes: 3

Views: 3054

Answers (1)

Amin Etesamian
Amin Etesamian

Reputation: 3699

Have you overridden on_stop() method of your app? Try this.

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()

Upvotes: 1

Related Questions