当后退按钮pressed的onPause不叫? [英] onPause not called when back button pressed?

查看:108
本文介绍了当后退按钮pressed的onPause不叫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的理解,显然是错误的,那的onPause()被称为每当后退按钮是pressed?现在在我的code,我已经把这个的onPause()事件:

It was my understanding, obviously wrong, that onPause() is called whenever the back button is pressed? Now in my code I've put this onPause() event:

@Override
protected void onPause(){
    super.onPause();        

    if(!_END_GAME){
        Builder _alert = new AlertDialog.Builder(this)
        .setMessage("onPause, with game NOT over!");
        _alert.setNeutralButton("OK.",
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                arg0.dismiss(); // Kills the interface
                System.runFinalizersOnExit(true);
                finish();
            }
        });
        _alert.setTitle("Your Score!");
        _alert.show();
    }

}

现在的问题是,该对话框不会推出什么那么以往,然后code错误的。我把对话框出现,试图以可视化的的onPause()被调用的地方,帮我调试其他一些变量和这样的。然而,正如我说从来没有被显示。任何想法,为什么这会是什么?是否有先于的onPause推出了功能()时,后退按钮pressed?预先感谢您的任何信息。

Now the problem is, the dialog does not launch what-so-ever, and then the code errors out. I put the dialog there to try to visualize where the onPause() was called and help me debug some other variables and such. Yet like I said it never even gets shown. Any ideas why this would be? Is there a function that is launched prior to onPause() when the back button is pressed? Thank you in advance for any info.

推荐答案

您应该通过重写检查后退按钮的onkeydown 不测试在onPause 的onPause 被调用时,您的活动<击>不再在后台叶前景;它不一定整理。 (您可以检查 isFinishing()了点。)请参阅的这里

You should check for the back button by overriding onKeyDown, not testing in onPause. onPause gets called whenever your activity is no longer in the background leaves the foreground; it is not necessarily finishing. (You can check isFinishing() for that.) See here for more info on handling the back key.

这篇关于当后退按钮pressed的onPause不叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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