winit icon indicating copy to clipboard operation
winit copied to clipboard

Android: MainEvent::Destroy does not exit the event loop (android_main() never returns)

Open Johannes0021 opened this issue 5 months ago • 2 comments

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:

  1. Swipe app to the "recent activities" view.
  2. Tap app icon -> "Pause app".
  3. Tap app icon again -> "Unpause app". -> App becomes unresponsive.

Case 2:

  1. Open the app.
  2. Swipe to the recent apps screen without fully closing it (it should keep running (no suspend)).
  3. Quickly swipe the app away and reopen it. -> The app sometimes becomes unresponsive.

Device 2: Samsung Galaxy A33 (Android 15)

  1. Launch the app.
  2. Enter Samsung's multi-window mode (floating window, not split-screen).
  3. Close the app using the "X" button in the window frame.
  4. 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

Johannes0021 avatar Jul 13 '25 15:07 Johannes0021

I tried to clean up this thread for clarity.

Johannes0021 avatar Jul 22 '25 18:07 Johannes0021

This might be a related issue: https://github.com/slint-ui/slint/issues/6626

Johannes0021 avatar Jul 22 '25 21:07 Johannes0021