打后退按钮在Android上时关闭应用程序 [英] Close app when hitting back button on android

查看:132
本文介绍了打后退按钮在Android上时关闭应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的登录活动就是你看到的第一个画面。当你点击后退按钮,它退出应用程序,不错。所以,我再次打开该应用程序。登录后,我现在在我的主要活动。我如何使它所以当我打的后退按钮现在,它退出应用程序,而不是要回登录活动?

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?

推荐答案

在推新活动,呼吁previous完成(),否则将继续在堆栈上,因此出现当你打回来,弹出当前活动。

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.

希望有所帮助。

这篇关于打后退按钮在Android上时关闭应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆