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));