My Quick Notes

Ain't Nobody Got Time to Read

android

1 articles

How to properly exit Bevy app on Android

Normally, a Bevy application can exit with AppExit, like:

fn exit_system(mut exit_event: MessageWriter<AppExit>) {
    exit_event.write(AppExit::Success);
}

But on Android, that is not enough and can cause the app fails to reopen. To completely exit the Bevy application on Android, we need to exit on the Android side too.

 .--------------------------------------.           .------------------------------.
|                  Bevy                  |         |            Android             |
|   .------------.     .------------.    |         |   .------------.               |
|  |    system    |   |     main     |   |         |  | MainActivity |              |
|   '-----+-+----'     '-----+-+----'    |         |   '-----+-+----'               |
|         | |    AppExit     | |         |         |         | |                    |
|         +-+--------------->| |         |         |         | |                    |
|                            | |     exitAppActivity         | |                    |
|                            +-+---------------------------->| |                    |
|                                        |         |         | +---.                |
|                                        |         |         | |   | finishAffinity |
|                                        |         |         | |   |                |
|                                        |         |         +-+<--'                |
|                                        |         |                                |
 '--------------------------------------'           '------------------------------'
Read More...