1. Onbackpressed method for covering activityOfficial explanation:
Called when the activity had detected the user ' s press of the back key.
The default implementation simply finishes the current activity, but you can override this to do whatever for you want.
@Override
public void onbackpressed () {
It is entirely up to you to control the return key logic, and the system is not in control, but there is a precondition for not intercepting the return key in the activity's onkeydown or onkeyup. Intercept: It is in onkeydown or onkeyup that the return key is processed (returns true after processing). Or return false will cause onbackpressed not to execute)// Do not intercept: Returns the super corresponding method in OnKeyDown and OnKeyUp (if two methods are overwritten, each return super.onkeydown,super.onkeyup)
}2, overwrite the activity of the onkeydown or onkeyup, intercept the return button
@Override
public boolean onKeyUp (int keycode, keyevent event) {
if (keycode = = Keycode.keycode_back) {
return Iscosumenbackkey ();
}
return false;
}
Private Boolean Iscosumenbackkey () {
Here do the return key control, if you handle the return key logic to return True, if return false, the representative continues to pass down the back event, the system takes control
return true;
} Example: The following code does not go to onbackpressed (the following three methods are covered in one activity) @Override
public void onbackpressed () {
}
@Override
public boolean onKeyUp (int keycode, keyevent event) {
if (keycode = = Keycode.keycode_back)
return false;
return false;
}
@Override
public boolean onKeyDown (int keycode, keyevent event) {
if (keycode = = Keycode.keycode_back)
Return Super.onkeydown (KeyCode, event);
return false;
}
The Android activity returns key control in two ways