Android: MainEvent::Destroy does not exit the event loop (android_main() never returns)
Description
I ran into a problem where the Android MainEvent::Destroy event didn't properly exit the event loop, preventing android_main() from returning.
Device 1: Google Pixel 9 (Android 16)
Case 1:
- Swipe app to the "recent activities" view.
- Tap app icon -> "Pause app".
- Tap app icon again -> "Unpause app". -> App becomes unresponsive.
Case 2:
- Open the app.
- Swipe to the recent apps screen without fully closing it (it should keep running (no suspend)).
- Quickly swipe the app away and reopen it. -> The app sometimes becomes unresponsive.
Device 2: Samsung Galaxy A33 (Android 15)
- Launch the app.
- Enter Samsung's multi-window mode (floating window, not split-screen).
- Close the app using the "X" button in the window frame.
- Reopening it via app icon or recent activities does not restart it. -> The app remains frozen.
Workaround:
In 'winit/winit-android/src/event_loop.rs' in the EventLoop::single_iteration() function, under the MainEvent::Destroy match arm:
match event {
// ...
MainEvent::Destroy => {
// XXX: maybe exit mainloop to drop things before being
// killed by the OS?
warn!("TODO: forward onDestroy notification to application");
// onPause -> onStop -> onDestroy, so suspended should be triggered beforehand?
self.window_target().exit(); // <- This is the workaround.
},
// ...
}
Not sure if this is the correct approach.
An issue I encountered afterwards is: https://github.com/rust-windowing/winit/issues/3325
Thanks for your great work on winit. I hope this report helps.
Device and Android version
Samsung Galaxy A33 (Android 15) Google Pixel 9 (Android 16)
Winit version
0.30.11
I tried to clean up this thread for clarity.
This might be a related issue: https://github.com/slint-ui/slint/issues/6626