Many users do not understand how to capture the back key event on the Android platform. The back key is the back key on the mobile phone. General software does not capture relevant information, which may lead to yourProgramSwitch to the background, and return to the desktop, there are two ways to get the event of this button on Android. 1. directly obtain the button and press the event. This method is compatible with Android 1.0 to Android 2.1 and is also a common method. You can directly override the onkeydown method of the activity,CodeAs follows:
@ Override
Public Boolean onkeydown (INT keycode, keyevent event ){
If (keycode = keyevent. keycode_back & event. getrepeatcount () = 0) {// If you press back, there are no duplicates
Toast. maketext (android123.this, "android development network back key test", 1). Show ();
Return true;
}
Return super. onkeydown (keycode, event );
}
There is a new method for Android 2.0 at the beginning. For activity, you can independently obtain the back key press event and directly rewrite the onbackpressed method. The Code is as follows:
@ Override
Public void onbackpressed (){
// The logic code is processed here. cwj prompts you to note that this method is only applicable to SDK 2.0 or later versions.
Return;
}
This article is transferred fromWww.35java.com