Capture the Home Key in Android

Source: Internet
Author: User

Override these two methods:

@ Override
Public Boolean onkeydown (INT keycode, keyevent event ){
// Todo auto-generated method stub

Intent intent = new intent (intent. action_main );
If (keyevent. keycode_home = keycode ){

Do something ...... // capture the Home Key to do your own thing

Intent. setflags (intent. flag_activity_new_task); // if it is called in a service, the new task id must be added.

Intent. addcategory (intent. category_home );
Startactivity (intent );
}
Return super. onkeydown (keycode, event );

}

 

@ Override
Public void onattachedtowindow (){
// Todo auto-generated method stub
This. getwindow (). settype (windowmanager. layoutparams. type_keyguard );
Super. onattachedtowindow ();
}

However, there is a small problem: when you exit the application, half a black screen will pop up. I don't know why. If you know, please leave a message to make progress together. Thank you!

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.