NativeActivity的未完成 [英] NativeActivity does not finish

查看:219
本文介绍了NativeActivity的未完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我称之为从JavaActivity一个NativeActivity的。我NativeActivity的的切入点是

I call a NativeActivity from a JavaActivity. The entry point of my NativeActivity is

 android_main(struct android_app* state)

在本月底,我称之为

At the end of this, I call

 ANativeActivity_finish

不过我的祖国的活动只是挂起,而不是返回到Java活动调用它(这是简单的使用 startActivity 调用)。现在看来似乎处于暂停状态。我可以得到它返回到previous活动的唯一方法是通过调用退出(0)在我android_main的结束,然而,这杀死的过程和原因其他问题。

However my native activity just hangs, instead of returning to the Java Activity that called it (it was called simply using startActivity). It seems like it is in a pause state. The only way I can get it to return to the previous activity is by calling exit(0) at the end of my android_main, however this kills the process and causes other issues.

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

How can I successfully exit my NativeActivity and return to the JavaActivity that called it?

推荐答案

我碰到了同样的问题。基本上,它为我的作品时ANativeActivity_finish(..)被称为主循环,因为它无效状态,并完成设置语句>的静态无效android_app_destroy调用ANativeActivity_finish(..)之后destroyRequested 1(结构android_app应用程序本身* android_app)(android_native_app_glue.c C:173)

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);
    }
  }
}

那么这是为时已晚,你我猜,但我花了这么多时间就可以了,因为我无法找到一个sultion所以我张贴在这里为大家谁运行到同样的问题。更多关于其他棘手的问题涉及到分离和附加的呼叫可以在这里找到:<一href="http://stackoverflow.com/questions/10166638/access-android-apk-asset-data-directly-in-c-without-asset-manager-and-copying">Access安卓APK资产直接在C ++中没有资产管理的数据和复制

这篇关于NativeActivity的未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆