我从 JavaActivity 调用 NativeActivity。我的 NativeActivity 的入口点是
android_main(struct android_app* state)
最后,我打电话给
ANativeActivity_finish
然而,我的本机活动只是挂起,而不是返回到调用它的 Java 活动(它只是使用startActivity
)。看起来像是处于暂停状态。我可以让它返回到上一个活动的唯一方法是调用exit(0)
在我的 android_main 结束时,但这会杀死进程并导致其他问题。
如何成功退出 NativeActivity 并返回到调用它的 JavaActivity?
我遇到了同样的问题。基本上,当在主循环中调用 ANativeActivity_finish(..) 时,它对我有用,因为它在 static 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);
}
}
}
好吧,我想对你来说已经太晚了,但我花了很多时间在这上面,因为我找不到解决方案,所以我将其发布在这里,供遇到同样问题的每个人使用。有关分离和附加调用的其他棘手内容的更多信息可以在这里找到:直接在c++中访问Android APK资源数据,无需Asset Manager和复制 https://stackoverflow.com/questions/10166638/access-android-apk-asset-data-directly-in-c-without-asset-manager-and-copying
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)