简体   繁体   English

在子活动中按下返回按钮后,Android主要活动的元素不响应

[英]Android main activity's elements do not respond after pressing the back button from child activity

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. android的后退按钮也是如此。 Although the back button flashes up after clicking on it, nothing happens. 尽管单击后退按钮后闪烁,但没有任何反应。

My guess is that it has something to do with android's memory management or the game loop. 我的猜测是,它与android的内存管理或游戏循环有关。 I destroy the game thread inside of my SurfaceView's surfaceDestroyed: 我销毁了SurfaceView表面中的游戏线程。

@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()方法,因此我看不到更深入地对其进行调试的方法。

The problem was that the running thread in the child activity was not correctly stopped - I was missing a setRunning(false) before joining. 问题是子活动中的正在运行的线程未正确停止-加入前我缺少setRunning(false)。 I assume that the UI Threads did their work anyway. 我认为UI线程仍然可以完成工作。 After fixing the thread, the back button works properly. 固定螺纹后,后退按钮可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM