问题描述
我要实现我的应用程序中的后退按钮功能。在实际应用中,每当我点击后退按钮中间我的控制将会直接登录页面,所以有人可以告诉我在哪里可以覆盖的onkeydown()
或 onBack pressed()
方法?
I want to implement the back button functionality in my application. In application whenever I'm clicking on back button in middle my control is going to login page directly, so can someone tell me where to override onKeyDown()
or onBackPressed()
methods?
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.e("back key pressed","Back key pressed");
return true;
}
return super.onKeyDown(keyCode, event);
}
因为我里面的onCreate和的onCreate外还写这个,但它不工作......
because I'm writing this inside onCreate and outside onCreate also, but it's not working ......
推荐答案
取决于你是否希望支持pre-的Android 2.0手机。该 onBack pressed()
方法加入到Android 2.0(API 5)。
Depends on whether or not you want to support pre-Android 2.0 phones. The onBackPressed()
method was added to Android 2.0 (API 5).
您可能需要阅读这篇文章在Android开发者博客的详细信息:
You may want to read this post on the Android Developer blog for details:
http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
这篇关于的onkeydown()或onBack pressed()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!