kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.33k stars 1.84k forks source link

on_stop never get's called when closing Android app. #2272

Open abstractdonut opened 4 years ago

abstractdonut commented 4 years ago

Checklist

class StopApp(App):

def on_stop(self):
    print("APP STOP APP STOP APP STOP")
    print("APP STOP APP STOP APP STOP")
    print("APP STOP APP STOP APP STOP")

def build(self):
    return Label(text='Hello world')

if name == 'main': StopApp().run()

--dist_name=stop --private . --package=com.example.stop --name "Stop" --bootstrap=sdl2 --requirements=python3,kivy==master,android,sdl2 --arch=armeabi-v7a --sdk_dir /home/user/android/ --ndk_dir /home/user/android/android-ndk-r19c/ --android_api 28 --ndk-api 21 --version 0.0.1 --debug


- [X] I reproduced the problem with the latest development version (`p4a.branch = develop`)
- [X] I used the grave accent (aka backticks) to format code or logs when appropriated

### Versions

- Python: 3.8
- OS: Android
- Kivy: 2.0.0rc3 
- Cython: 0.29.13
- OpenJDK:

### Description

I encountered this problem with an app that I'm developing which works as expected on Ubuntu 18 and Windows, but which fails on Android. The failure causes settings to not persist between successive runs due to on_stop not being called as expected.

I wrote the small example above to isolate the problem.

Expectation:

APP STOP APP STOP APP STOP APP STOP APP STOP APP STOP APP STOP APP STOP APP STOP


should appear in the shell or in logcat.

What happens:
When launching the program from android_studio the expected string never appears in Logcat.

buildozer was not used, only p4a.
ghost commented 4 years ago

on my app I was trying to use on_setop to save the user setting and on_start to read the setting when start the app but it;s not working on android, but if use on_pause() and on_resume() instead my app works well

mzakharocsc commented 4 years ago

I also found that pressing the '<' (back arrow) on Android UI, the 'on_stop()" method is called correctly. What is not working is closing the app through the 'application list'.