在 Android 中启动新活动并完成当前活动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11308198/
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
Start new Activity and finish current one in Android?
提问by pixel
Currently I'm starting a new Activity
and calling finish
on a current one.
目前我正在开始一个新的Activity
并呼吁finish
当前的。
Is there any flag that can be passed to Intent
that enables finishing current Activity
without a need to call finish
manually from code?
是否有任何标志可以传递到无需从代码手动调用Intent
即可完成当前操作?Activity
finish
回答by Simon Dorociak
You can use finish()
method or you can use:
您可以使用finish()
方法,也可以使用:
android:noHistory="true"
And then there is no need to call finish()
anymore.
然后就没有必要再打电话finish()
了。
<activity android:name=".ClassName" android:noHistory="true" ... />
回答by Avi Kumar Manku
Use finish
like this:
finish
像这样使用:
Intent i = new Intent(Main_Menu.this, NextActivity.class);
finish(); //Kill the activity from which you will go to next activity
startActivity(i);
FLAG_ACTIVITY_NO_HISTORY
does the opposite. New activity is not saved in history, whereas OP wants previous Activity being finished.
FLAG_ACTIVITY_NO_HISTORY
相反。新活动不会保存在历史记录中,而 OP 想要完成之前的活动。
To learn more on using Intent.FLAG_ACTIVITY_NO_HISTORY
read: http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY
要了解有关使用Intent.FLAG_ACTIVITY_NO_HISTORY
阅读的更多信息:http: //developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY
回答by 10s
FLAG_ACTIVITY_NO_HISTORY when starting the activity you wish to finish after the user goes to another one.
FLAG_ACTIVITY_NO_HISTORY 在用户转到另一个活动后开始您希望完成的活动时。
http://developer.android.com/reference/android/content/Intent.html#FLAG%5FACTIVITY%5FNO%5FHISTORY
http://developer.android.com/reference/android/content/Intent.html#FLAG%5FACTIVITY%5FNO%5FHISTORY