我想阻止 android 中的硬件后退按钮,以防止返回到其他 Activity .. 提前致谢...
最佳答案
以下代码可让您在平台的所有版本上正确处理 Activity 中的返回键:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( Integer.valueOf(android.os.Build.VERSION.SDK) < 7 //Instead use android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
return;
}
来源:http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
关于android - 在 android 中阻止后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3988478/