Skip to content

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

@Johannes0021

Description

@Johannes0021

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: #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    B - bugDang, that shouldn't have happenedDS - androidAffects the Android backend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions