From 7f35a4ab6b735c33a5c05406c70193cd584c4aa6 Mon Sep 17 00:00:00 2001 From: Le Juez Victor <90587919+Bigfoot71@users.noreply.github.com> Date: Tue, 20 Jun 2023 00:58:21 +0200 Subject: [PATCH] Review of `void android_main(struct android_app *app)` --- src/rcore.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/rcore.c b/src/rcore.c index 27b60ae4a..6d81405d4 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -720,14 +720,11 @@ void android_main(struct android_app *app) // NOTE: Return codes != 0 are skipped (void)main(1, (char *[]) { arg0, NULL }); - // Finish native activity - ANativeActivity_finish(CORE.Android.app->activity); - // Android ALooper_pollAll() variables int pollResult = 0; int pollEvents = 0; - // Wait for app events to close + // Wait for application events before requesting the activity to close while (!CORE.Android.app->destroyRequested) { while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void **)&CORE.Android.source)) >= 0) @@ -736,8 +733,14 @@ void android_main(struct android_app *app) } } - // WARNING: Check for deallocation and ensure no other processes are running from the application - exit(0); // Closes the application completely without going through Java + // Finish native activity + ANativeActivity_finish(CORE.Android.app->activity); + + // WARNING: Make sure you free resources properly and no other process is running from Java code or other. + // NOTE: You can use JNI to call a NativeLoader method (which will call finish() from the UI thread) + // to handle the full close from Java, without using exit(0) like here. + + exit(0); // Close the application directly, without going through Java } // NOTE: Add this to header (if apps really need it)