From 10cbc84384d643a4e6d9df1fae89ba3127bc0d0c Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 24 Jul 2021 23:54:30 +0200 Subject: [PATCH] ndk-glue: Finish native activity after returning from `main()` When an application returns its control flow back from `main()` it is generally assumed to be done polling on the looper and wishes to terminate. Android is made aware of this by calling `ANativeActivity_finish`, otherwise it'll continue sending input events and eventually ANR as the app didn't consume them anymore. --- ndk-glue/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ndk-glue/src/lib.rs b/ndk-glue/src/lib.rs index 96b64de8..16fcbc77 100644 --- a/ndk-glue/src/lib.rs +++ b/ndk-glue/src/lib.rs @@ -198,7 +198,12 @@ pub unsafe fn init( signal_looper_ready.notify_one(); } - main() + main(); + + NATIVE_ACTIVITY + .take() + .expect("Native activity should not have been taken before main() returns!") + .finish() }); // Don't return from this function (`ANativeActivity_onCreate`) until the thread