Я столкнулся с той же проблемой. В основном это работает для меня, когда ANativeActivity_finish (..) вызывается в основном цикле, потому что он делает недействительными состояния и завершает само приложение, устанавливая state-> destroyRequested в 1 после вызова ANativeActivity_finish (..) в 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);
}
}
}
Я полагаю, что для вас уже слишком поздно, но я потратил столько времени на это, потому что не смог найти решение, поэтому я публикую его здесь для всех, кто сталкивается с такими же проблемами. Подробнее о других хитрых вещах, связанных с вызовами отсоединения и присоединения, можно узнать здесь: Доступ к данным Android APK Asset напрямую в c ++ без Asset Manager и копирования