gpt4 book ai didi

android - NativeActivity 没有完成

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:44:43 25 4
gpt4 key购买 nike

我从 JavaActivity 调用 NativeActivity。我的 NativeActivity 的入口点是

 android_main(struct android_app* state)

最后,我打电话

 ANativeActivity_finish

但是我的 native Activity 只是挂起,而不是返回到调用它的 Java Activity (它只是使用 startActivity 调用的)。好像是处于暂停状态。我可以让它返回到之前的 Activity 的唯一方法是在我的 android_main 结束时调用 exit(0),但是这会终止进程并导致其他问题。

如何才能成功退出我的 NativeActivity 并返回到调用它的 JavaActivity?

最佳答案

我遇到了同样的问题。基本上当在主循环中调用 ANativeActivity_finish(..) 时它对我有用,因为它使状态无效并通过在调用 ANativeActivity_finish(..) 后将 state->destroyRequested 设置为 1 来完成应用程序本身 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);
}
}
}

好吧,我想这对你来说已经太晚了,但我花了很多时间在这上面,因为我找不到问题,所以我把它贴在这里,供遇到同样问题的每个人使用。有关与分离和附加调用相关的其他棘手内容的更多信息,请参见此处:Access Android APK Asset data directly in c++ without Asset Manager and copying

关于android - NativeActivity 没有完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8088086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com