Android--Home button

Source: Internet
Author: User

In the game often need to listen to the Android home button, when the home button under pressure, often need to do some state preservation, sound effects, such as the operation, 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.

    • Home key in the ins and outs

    • Receive the Home key broadcast event in the app

First, customize a broadcastreceiver:

classHomekeyeventbroadcastreceiverextendsBroadcastreceiver {Static FinalString System_reason = "REASON"; Static FinalString System_home_key = "HomeKey";//Home Key    Static FinalString System_recent_apps = "Recentapps";//Long Home key@Override Public voidOnReceive (Context context, Intent Intent) {String action=intent.getaction (); if(Action.equals (intent.action_close_system_dialogs)) {String reason=Intent.getstringextra (System_reason); if(Reason! =NULL) {                  if(Reason.equals (System_home_key)) {//Home key processing point                                      } Else if(Reason.equals (System_recent_apps)) {//Long Home key processing point                }              }          }      }  }

Second, the generated and registered

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

This way, we can do the home button processing in the app!

I'm the dividing line of the king of the Land Tiger.

Reference: http://blog.csdn.net/imyfriend/article/details/8293399

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.