如何关闭应用程序?

发布于 2024-12-11 02:17:26 字数 593 浏览 1 评论 0原文

我有一个启动屏幕,其中有一些代码我只想调用一次,因此在显示启动屏幕后,它会转到我的主游戏,并且我不希望它再次返回启动屏幕,直到游戏再次启动。但是当我返回主屏幕时,它又回到初始屏幕。当从主屏幕按下后退按钮而不是返回到初始屏幕时,如何使游戏关闭?

这是我现在在主游戏中所拥有的内容,但它仍然可以追溯到飞溅......

   @Override  
  public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {  
                Toast.makeText(getApplicationContext(),"back was pressed",Toast.LENGTH_LONG).show();
                finish();

            return true;
            }

            return super.onKeyDown(keyCode, event);
        }

i have a splash screen that has some code that i only want called once so after showing the splash screen it goes to my main game, and i don't want it going back to the splash screen again until the game is launched again. but when i hit back on my main screen, it goes back to the splash screen. how do i make the game close when the back button is pressed from the main screen instead of going back to the splash screen?

here is what i have right now on my main game, but it still goes back to the splash...

   @Override  
  public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {  
                Toast.makeText(getApplicationContext(),"back was pressed",Toast.LENGTH_LONG).show();
                finish();

            return true;
            }

            return super.onKeyDown(keyCode, event);
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黯然#的苍凉 2024-12-18 02:17:26

在执行 startActivity() 后立即在启动活动中调用 finish() :)

Call finish() in the splash activity right after you do startActivity() :)

以可爱出名 2024-12-18 02:17:26

如果您要启动活动,则可以使用 FLAG_ACTIVITY_NO_HISTORY。请参阅以获取参考。我相信如果这是您的初始活动,您也可以以某种方式做同样的事情。

If you are starting the Activity you can use FLAG_ACTIVITY_NO_HISTORY. See this for a reference. I'm sure you can do the same somehow if it is your initial activity.

浅忆流年 2024-12-18 02:17:26

您可以在 Splash 活动的 onResume 方法中调用 finish()。杰克的解决方案可能是最好的。

You could put a call to finish() in your onResume method for the Splash activity. Jack's solution is probably best though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文