Description
Describe the bug
On desktop, the on_exit
function is called without issues when closing the app. But on Android, it is not called. This is an issue when using persistence, since the save
function is also not called (this seems to be related as save
should be called just before on_exit
according to the docs) and therefore data is lost if for example some settings are changed and then the user closes the app before the next timed save
function call.
To Reproduce
Steps to reproduce the behavior:
- Clone the https://github.com/Pandicon/egui-android-example/tree/%60on_exit%60-not-called repository where I set up a basic Android app which showcases this issue
- Run the app (initialise the cargo mobile project with
cargo mobile init
, connect an Android device, allow USB debugging, and docargo mobile run
) - Run
adb logcat
to see the logs, you can either somehow filter for a specific app or just redirect it into a text file and search for the relevant logs - Let it run for a while - you will see
saving!
being logged every 30 seconds (at least for me). - Wait to be like 10 seconds past the last
saving!
log and close the app. Look for a newsaving!
log (this is why one should wait - to be certain if a given log is the timed one) and anexiting!
log. Neither of them exist, so the app was closed withoutsave
oron_exit
being called.
Expected behavior
on_exit
and save
are called fine when closing the app (ideally save
would also be called when putting the app into background, i.e. "leaving it" as it may get killed by the OS later, but I am not sure if that would not emit the on_exit
-triggering event - this would require some testing)
Smartphone (please complete the following information):
- Device: Galaxy Tab S8
- OS: Android 14, One UI 6.1.1
Additional context
When using winit, I was able to listen for an event that indicated that the app was being closed/put into the background, where I could call the save
function manually. So I feel like it is not a general issue with Android emitting events weirdly or something and that if winit is able to handle it, then eframe should also be.