In Android, let the button have the return key function and rewrite the return key function _android

Source: Internet
Author: User

Let the button have the Return key function is very simple, in the Click event Plus Finish (); OK.
Such as:

Copy Code code as follows:

public void OnClick (View v) {

Finish ();

}


Finish () simply exits the activity from its current state, but the resource is not cleaned up.
In fact, the Android mechanism determines that users cannot completely exit application, that is, using System.exit ().
Android decides when to release the program from memory, and when the system does not have available memory, it will destroy the application in a certain priority.
The Android phone operating system has a garbage disposal mechanism, so don't worry about it, use the finish () method.

Override Return Key:

Copy Code code as follows:

public boolean onKeyDown (int keycode,keyevent event) {

if (keycode = = Keyevent.keycode_back && event.getrepeatcount () = = 0) {
Here rewrite the return key
return true;
}
return false;

}

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.