Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android为什么不';活动结束_Android - Fatal编程技术网

Android为什么不';活动结束

Android为什么不';活动结束,android,Android,我的游戏有问题-当live为0时,它应该在屏幕上显示游戏并完成游戏活动,但屏幕会冻结。 曲面中的代码为: if(live <= 0){ try { gameThread.setGameRunning(false); gameThread.join(); } catch (InterruptedException e) { e.printStackTrace(); }

我的游戏有问题-当live为0时,它应该在屏幕上显示游戏并完成游戏活动,但屏幕会冻结。 曲面中的代码为:

if(live <= 0){
        try {
            gameThread.setGameRunning(false);
            gameThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        gameOverHandler.post(new Runnable() {
            @Override
            public void run() {
                gameOver.onGameOver(score);
            }
        });

    }
游戏线程循环画布绘图,引擎循环角色的移动

我希望你能帮助我。
谢谢

您必须在代码中的某个地方使用

gameOverHandler = new Handler();

尝试将其替换为

gameOverHandler = new Handler(Looper.getMainLooper());


取决于您实际使用的类。

Sry我的互联网大约在周末关闭,我已与构造函数解决了它

public GameSurface(Context context, OnGameOver onGameOver){
...
}
在主要活动中

gameSurface = new GameSurface(this, this);
并实施了一系列措施
对我的代码进行了一点重写,但效果不错……

可能是gameOverHandler不是在UI线程上创建的,而是在后台线程上创建的。在这种情况下,post不会将执行带到UI线程,而finish可能没有适当的效果。尝试使用新的处理程序(Looper.getMainLooper())在UI线程上创建gameOverHandler,并尝试它是否有效。我理解你的意思,这是正确的,因为在表面上,gameOver从未分配,但我必须如何做我不明白-->Looper.getMainLooper()的意思。请描述一下它好吗?谢谢,但它不起作用。。。我找到了一个解决方案,我没有声明接口在UI中..很好!如果你能发布正确的解决方案并标记它。未来的用户将得到很大帮助。
gameOverHandler = new GameOverHandler(Looper.getMainLooper());
public GameSurface(Context context, OnGameOver onGameOver){
...
}
gameSurface = new GameSurface(this, this);