我不希望我的活动在按下后退按钮时被破坏。我的应用程序与 1.6 SDK 兼容。参考http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html和Override back button to act like home button,我选择了以下代码:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// For versions lower than 2.0
if (Utility.buildDet.getDeviceBuildAPI() <= Utility.buildDet.getBuildApi()
&& keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
onBackPressed();
return super.onKeyDown(keyCode, event);
}
// In any version, this function will be called
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.
Log.i(TAG, "##### BACK KEY IS PRESSED");
this.moveTaskToBack(true); // on false, it shows moveTaskToBack: 11
return;
}
当我按下后退按钮时,我会记录这些日志
: ##### BACK KEY IS PRESSED
INFO/ActivityManager(51): moveTaskToBack: 10
: !!!!!!! Into onPause
: !!!!!!! Into onStop
: !!!!!!! Into DESTROY
我没有覆盖 moveTasToBack()。Anu clu 我该怎么做才能在按下后退按钮时不被破坏。也许我只想忽略按钮或隐藏活动。
任何线索,为什么它没有按预期工作。
谢谢