Back key event capture on Android

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.