我遇到了同样的问题。基本上它在主循环中调用 ANativeActivity_finish(..) 时对我有用,因为它使状态无效并通过在静态 void android_app_destroy(struct android_app 中调用 ANativeActivity_finish(..) 后将 state->destroyRequested 设置为 1 来完成应用程序本身* 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);
}
}
}
好吧,我想对你来说已经太晚了,但是我花了很多时间在上面,因为我找不到一个 sultion 所以我把它贴在这里给遇到同样问题的每个人。可以在此处找到有关与分离和附加调用相关的其他棘手内容的更多信息:Access Android APK Asset data directly in c++ without Asset Manager and copying