I got two activities in my game application. One parent menu activity with two buttons, each having a onClick, and one child (game) activity containing the game loop.

我的游戏应用程序中有两项活动。一个父菜单活动,带有两个按钮,每个按钮都有一个onClick,以及一个包含游戏循环的子(游戏)活动。

When I press the back button from the game activity, the menu seems to be properly resumed: Both buttons are at the right position and look like before.

当我按下游戏活动中的后退按钮时,菜单似乎正确恢复:两个按钮位于正确的位置,看起来像以前一样。

The problem is that the buttons don't work anymore. Same goes for the android's back button. Although the back button flashes up after clicking on it, nothing happens.

问题是按钮不再起作用。同样适用于android的后退按钮。虽然点击它后后退按钮闪烁,但没有任何反应。

My guess is that it has something to do with android's memory management or the game loop. I destroy the game thread inside of my SurfaceView's surfaceDestroyed:

我的猜测是它与android的内存管理或游戏循环有关。我摧毁了SurfaceView的surfaceDestroyed中的游戏线程:

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    boolean retry = true;
    while (retry) {
        try {
            gameEngine.join();
            retry = false;
        } catch (InterruptedException e) {

        }
    }
}

I use no custom overriden methods for resuming and restarting. Since the activity's appearance resumes finely and the onResume() method is called on resuming to the menu activity, I see no way to debug into it deeper.

我没有使用自定义覆盖方法来恢复和重新启动。由于活动的外观恢复正常,并且onResume()方法在恢复到菜单活动时被调用,我看不到更深入的调试。

1 个解决方案

#1


0

The problem was that the running thread in the child activity was not correctly stopped - I was missing a setRunning(false) before joining. I assume that the UI Threads did their work anyway. After fixing the thread, the back button works properly.

问题是子活动中正在运行的线程未正确停止 - 我在加入之前错过了一个setRunning(false)。我假设UI线程无论如何都做了他们的工作。固定线程后,后退按钮正常工作。

更多相关文章

  1. android多线程数据存储 - ThreadLocal的工作原理
  2. java基础---多线程---java内存模型
  3. JSP页面中有一个按钮 点击之后执行JAVA文件
  4. java 使用Callable和Future返回线程执行的结果
  5. Java多线程聊天对话框
  6. Android 多线程下载文件原理霸气解析介绍 (完结版)-----greendao
  7. Java多线程六:线程优先级和yield()让步函数
  8. java多线程爬虫
  9. javafx 和netty 混合使用出现线程不一致问题,求大神指点

随机推荐

  1. Android中String资源文件的format方法
  2. android初级
  3. Android 开机图片/文字/动画 修改
  4. Android震动---启动、循环、取消控制
  5. Android(安卓)Studio 快捷键
  6. Android(一) 安卓概述
  7. Android Mac开发Android推荐软件
  8. android:layout_paddingLeft和android:la
  9. Android(安卓)NDK开发篇(一) windows免cygw
  10. Android引路蜂地图开发包