Close app when hitting back button on android

2019-04-06 18:55发布

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?

2条回答
放荡不羁爱自由
2楼-- · 2019-04-06 19:51

try this one @Override public void onBackPressed() {

super.onBackPressed(); finish();

}

查看更多
萌系小妹纸
3楼-- · 2019-04-06 19:52

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.

查看更多
登录 后发表回答