座后退按钮在安卓按钮

2023-09-04 07:31:32 作者:死亡边缘

我想从回到其他活动阻止硬件后退按钮在Android中,以prevent ..   在此先感谢...

I want to block hardware back button in android ,in order to prevent from going back to other activity.. Thanks in advance...

推荐答案

下面是code,可让您正确处理活动的返回键上的所有平台版本:

Here is code that allows you to handle the back key in an activity correctly on all versions of the platform:

@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;
}

sources:http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html

sources:http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html