Listen to Android's home button [go]

Source: Internet
Author: User

Turn from: here

Often need to listen to the Android home button, when the home button under pressure, often need to do some state preservation, sound effects stop and other operations, then how to do to hear the home button? We know that home is a system key and cannot be handled by onkey these functions in the app. To properly handle the home button, you first need to look at the home button under pressure, what the system did.

Second, the app for the Home key broadcast event reception

First, customize a broadcastreceiver:

1     classHomekeyeventbroadcastreceiverextendsBroadcastreceiver {2 3         Static FinalString System_reason = "REASON";4         Static FinalString System_home_key = "HomeKey";//Home Key5         Static FinalString System_recent_apps = "Recentapps";//Long Home key6         7 @Override8          Public voidOnReceive (Context context, Intent Intent) {9String action =intent.getaction ();Ten             if(Action.equals (intent.action_close_system_dialogs)) { OneString reason =Intent.getstringextra (System_reason); A                 if(Reason! =NULL) { -                     if(Reason.equals (System_home_key)) { -                         //Home key processing point the                          -}Else if(Reason.equals (System_recent_apps)) { -                         //Long Home key processing point -                     } +                 } -             } +         } A}

Second, the generated and registered

1         New homekeyeventbroadcastreceiver (); 2         New Intentfilter (intent.action_close_system_dialogs));

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.