Close app when hitting back button on android

爱⌒轻易说出口 提交于 2019-12-21 09:35:03

问题


So my login Activity is the first screen you see. When you hit the back button, it exits the app, good. So I open up the app again. After logging in, I am now in my main Activity. How do I make it so when I hit the back button now, it exits the app rather than going back to the login Activity?


回答1:


When you push the new activity, call finish() on the previous, otherwise it will remain on the stack, therefore appearing when you hit back and pop the current activity.

Hope that helps.




回答2:


try this one @Override public void onBackPressed() {

super.onBackPressed(); finish();

}



来源:https://stackoverflow.com/questions/5902464/close-app-when-hitting-back-button-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!