I run into the same problem. Basically it works for me when ANativeActivity_finish(..) is called in the main loop, because it invalidates the states and finishes the app 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);
}
}
}
Well it is too late for you I guess, but I spent so much time on it because I couldn't find a sultion so I post it here for everyone who runs into the same problems. More about other tricky stuff related to the detach and attach calls can be found here: Access Android APK Asset data directly in c++ without Asset Manager and copying