Public void onBackPressed (){
AlertDialog. Builder builder = new Builder (LawdaquanActivity. this );
Builder. setIcon (R. drawable. imagebutton5 );
Builder. setTitle ("prompt ");
Builder. setMessage ("Do you really want to exit the legal information software? ");
Builder. setPositiveButton ("yes ",
New android. content. DialogInterface. OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog, int which ){
Intent I = new Intent (Intent. ACTION_MAIN );
I. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK );
I. addCategory (Intent. CATEGORY_HOME );
StartActivity (I );
}
});
Builder. setNegativeButton ("no ",
New android. content. DialogInterface. OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog, int which ){
Dialog. dismiss ();
}
});
Builder. create (). show ();
}
------------- Quit
Exit application implementation: you can write a method by yourself, for example:
Public void exitProgrames {
Intent startMain = new Intent (Intent. ACTION_MAIN );
StartMain. addCategory (Intent. CATEGORY_HOME );
StartMain. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK );
StartActivity (startMain );
Android. OS. Process. killProcess (android. OS. Process. myPid ());
-------------- Rewrite ONKEYDOWN
Public boolean onKeyDown (int keyCode, KeyEvent event ){
If (keyCode = KeyEvent. KEYCODE_BACK ){
New AlertDialog. Builder (this)
. SetIcon (R. drawable. title)
. SetTitle ("Exit software ")
. SetMessage ("withdraw from legal instruments software ")
. SetPositiveButton ("no ",
New DialogInterface. OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog,
Int which ){
// TODO Auto-generated method stub
}
}). SetNegativeButton ("exit", new OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog, int which ){
// TODO Auto-generated method stub
Finish ();
}
}). Create (). show ();
}
Else {
Return super. onKeyDown (keyCode, event );
}
// TODO Auto-generated method stub
Return super. onKeyDown (keyCode, event );
}
----------- False logout
Intent I = new Intent (Intent. ACTION_MAIN );
I. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK );
I. addCategory (Intent. CATEGORY_HOME );
StartActivity (I );
Finish ();
From the column of gongzibai