kivy / kivy/python-for-android

on_stop never get's called when closing Android app.

Open
#2,272 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
8.9k
Forks
2k
Avg merge
12h 20m
Merged PRs (30d)
9

Description

### Checklist

- [X] the issue is indeed a bug and not a support request
- [X] issue doesn't already exist: https://github.com/kivy/python-for-android/issues
- [X] I have a short, runnable example that reproduces the issue
```
from kivy.app import App
from kivy.uix.label import Label

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.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the runnable Kivy example with the listed p4a SDL2 arguments and tracing the Android close/lifecycle path around App.on_stop and logcat. Done means closing the generated APK invokes on_stop so the three expected lines appear in logcat and the app's settings can persist across runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, python
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.