Java 按下后退按钮时避免启动屏幕活动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20933627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Avoid splash screen activity when pressing Back button
提问by user3162478
In my application, I've two activities. First is a splash screen, which simply shows the application name and few other info. Upon clicking on the splash screen activity, I'm loading the main activity. My app works fine, but I'm facing a small issue. If I press back button from my main activity, control is going to splash screen activity. But I don't want to show the splash screen activity again, I want to avoid splash screen activity when pressing Back button.
在我的应用程序中,我有两个活动。首先是一个闪屏,它只显示应用程序名称和其他一些信息。单击启动屏幕活动后,我正在加载主要活动。我的应用程序运行良好,但我面临一个小问题。如果我从我的主要活动中按下后退按钮,控制将启动屏幕活动。但我不想再次显示闪屏活动,我想在按下后退按钮时避免闪屏活动。
Is it possible? If so how?
是否可以?如果是这样怎么办?
采纳答案by Gokul Nath KP
In your AndroidManifest.xml
file, add android:noHistory="true"
attribute in your splash screen <activity>
.
在您的AndroidManifest.xml
文件中,android:noHistory="true"
在您的启动画面中添加属性<activity>
。
回答by FxRi4
As I understand, you want the splash activity to not show after changing activity. You should note activities save On Stack and with starting new activity push on it and with finish you pop on top stack. I think that if you the call finish()
method your problem fix as in your splash screen activity where you call StartActivity insert finish()
after
据我了解,您希望在更改活动后不显示启动活动。您应该注意活动保存在堆栈上,并在开始新活动时推送它,完成后弹出堆栈顶部。我认为,如果您使用 callfinish()
方法,您的问题将在您调用 StartActivityfinish()
之后插入的启动屏幕活动中解决
public void onClick(View v) {
Intent intent = new Intent(Main.this, Splash.class);
startActivity(intent);
finish();
}
Hope to be useful :)
希望有用:)
回答by Jaswant Singh
You can just call
你可以打电话
finish();
In your Splash screen when you jump to the second screen.
当您跳转到第二个屏幕时,在您的启动画面中。