I am facing the same problem. This basically works for me when ANALActivity_finish (..) is called in the main loop because it invalidates the state and terminates the application itself by setting state-> destroyRequested to 1 after calling ANativeActivity_finish (..) in static void android_app_destroy (struct android_app * android_app) (android_native_app_glue.c C: 173).
void android_main(struct android_app* state) { // Attach current state if needed state->activity->vm->AttachCurrentThread(&state->activity->env, NULL); ... // our main loop for the app. Will only return once the game is really finished. while (true) { ... while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,(void**)&source)) >= 0) { ... // Check if we are exiting. Which is the case once we called ANativeActivity_finish(state->activity); if (state->destroyRequested != 0) { // Quit our app stuff herehere // detatch from current thread (if we have attached in the beginning) state->activity->vm->DetachCurrentThread(); // return the main, so we get back to our java activity which calle the nativeactivity return; } } if (engine.animating) { // animation stuff here } // if our app told us to finish if(Closed) { ANativeActivity_finish(state->activity); } } }
Itβs good that I was too late, but I spent so much time on it because I could not find the sult, so I post it here for everyone who is facing the same problems. More information about other difficulties associated with disconnecting and connecting can be found here: Accessing Asset Android APK data directly in C ++ without Asset Manager and copying
source share