本文介绍了当后退按钮是pressed的Andr​​oid应用程序紧密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

您好我在做我的应用程序的修改这是我想要单击后退按钮后关闭我的应用程序。这听起来常见的吧?不过这到底发生了什么,以我的应用程序。我有3个屏幕:起始页,游戏页面和分数页。 $ P $从开始页面pssing启动按钮后,将启动游戏页面的意图。完成游戏后,游戏页面会再移动到意向得分页面,当后退按钮从积分页面pssed $ P $,意图将在起始页这样过去了:

Hi I made a modification in my app which is I want to close my app after clicking the back button. This might sound common right? but this is what exactly happens to my app. I have 3 screens: Start Page, Game Page and Score Page. after pressing the start button from the Start page it will start the Game Page Intent. After finishing the game the Game Page will then move the intent into Score Page and when the back button is pressed from the Score Page, the intent will be passed on the Start Page like this:


  1. 启动页面 - >游戏页

  2. 游戏首页 - >评分页

  3. 分数页面(当后退按钮是pressed) - >启动页

我现在就去后回到起始页面,当我$ P $再次pssed后退按钮,而不是退出应用程序它只是回到积分页面,再如果我pressed后退按钮它会去初始页再犯死循环。我把这个code到我的开始页,但它并没有解决我的问题:

Now after I go back to the Start Page when I pressed the back button again instead of exiting the app it will just go back to the Score Page and again If I pressed the back button it will go to the Start Page again making an endless loop. I placed this code to my Start Page but it doesn't solve my problem:

@Override
public void onBackPressed() {
    Startup.this.finish();
}

我需要改变我的意图的流量或有这一个可能的解决方案?

Do I need to change the flow of my intents or there is a possible solution for this one?

推荐答案

或从分数页面调用开始页时,你可以使用该标志Intent.FLAG_ACTIVITY_CLEAR_TOP。

Or you can just use the flag Intent.FLAG_ACTIVITY_CLEAR_TOP when calling the Start page from the Score page.

Intent intent = new Intent(this, StartActivity.class)
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

这篇关于当后退按钮是pressed的Andr​​oid应用程序紧密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:43