The Home key function for shielding activity, dialog style activity, and alertdialog is as follows:
1. Disable the Home key function of the activity.
@ Override
Public void onattachedtowindow (){
This. getwindow (). settype (windowmanager. layoutparams. type_keyguard );
Super. onattachedtowindow ();
}
2. Shielding the Home key function of a dialog style Activity
@ Override
Public void onattachedtowindow (){
This. getwindow (). settype (windowmanager. layoutparams. type_keyguard_dialog );
Super. onattachedtowindow ();
}
The reason for distinguishing this from activity is that if the dialog style activity uses the first method, the background of the dialog style activity will become black rather than transparent.
3. Shielding alertdialog's home key function
Alertdialog d = B. Create ();
D. getwindow (). settype (windowmanager. layoutparams. type_system_alert );
The Home key is not blocked.
In the sleep mode of a music player, to ensure that the user only performs operations on the current prompt box when the sleep shutdown prompt box is displayed, the Home Key is blocked, just like canceling the shutdown operation or confirming the shutdown operation must be performed when the mobile phone is going to shut down, unless the confirmation is completed to close this dialog box, the operation cannot be performed on other interfaces.
Sleepdialog = B. Create ();
Sleepdialog. getwindow (). settype (windowmanager. layoutparams. type_system_alert );
Sleepdialog. Show ();
Home Key listening function:
@ Override
Public Boolean onkeydown (INT keycode, keyevent event)
{// Todo auto-generated method stub
If (keyevent. keycode_home = keycode)
Android. OS. process. killprocess (Android. OS. process. mypid ());
Return super. onkeydown (keycode, event );
}
================================== Reload a Home Key listener function below:
This article is from the csdn Dandan blog. For more information, see the source:
Http://blog.csdn.net/dany1202/archive/2011/06/14/6543769.aspx
Support originality
Registration:
View plain
Intentfilter filter = new intentfilter (intent. action_close_system_dialogs );
Mclosesystemdialogsreceiver = new closesystemdialogsintentreceiver ();
Registerreceiver (mclosesystemdialogsreceiver, filter );
Listener:
View plain
Private class closesystemdialogsintentreceiver extends broadcastreceiver {
@ Override
Public void onreceive (context, intent ){
String reason = intent. getstringextra ("reason ");
Log. D (TAG, "closesystemdialogsintentreceiver reason is" + reason );
If ("homekey". Equals (reason )){
Log. D (TAG, "homekey click ===================== ");
// Editwidget. This. Finish ();
Keyhomeflag = true;
}
}
}
The above function can listen to the Home Key instead of other keys after the home key function is complete.