简体   繁体   中英

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.

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.

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:

@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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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