Android-按下后退按钮时如何退出活动?
可能重复:
Android按下后退按钮应退出该应用
Possible Duplicate:
android pressing back button should exit the app
我正在建立一个注册和登录屏幕,仅用于练习.因此,我放置了SharedPreferences,以便当用户再次打开应用程序时,它将引导他们进入登录活动,而不是从注册重新开始.但是,当我从登录活动中按返回按钮时,仍然需要我重新注册活动,这可能会更改已保存的SharedPreferences.我想禁用此功能,如何在用户按下后退按钮时简单地退出应用程序?
I'm building a register and login screen just for an exercise. So I put SharedPreferences so that when user open the app again, it will direct them to login activity and not start again from register. However, when I press back button from login activity it still take me back to register activity which could change the already saved SharedPreferences. I wanna disable this function, how to simply exit the app when user press the back button?
谢谢
如果您从不希望后退按钮返回到注册屏幕,最干净的解决方案是将其从活动历史记录中排除使用清单中的 noHistory
属性,即
If you never want the back button to return to the registration screen, the cleanest solution would be to exclude it from the activity history using the noHistory
attribute in the manifest, i.e.
<activity
android:name=".RegistrationActivity"
...
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>