Android program when clicking the fallback button, if there is only one activity, call the finish () method can exit the interface, if there are multiple interfaces, when invoking the method, will only destroy the current activity, showing the top of the stack other activity, in other words, Is that you cannot exit the entire application. The following is a quick way to exit the entire application code:
?
1234567891011121314151617181920212223 |
private void showTips() {
AlertDialog alertDialog =
new AlertDialog.Builder(
this
).setTitle(
"提醒"
)
.setMessage(
"是否退出程序"
)
.setPositiveButton(
"确定"
,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
Intent intent =
new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
}
}).setNegativeButton(
"取消"
,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
return
;
}
}).create();
// 创建对话框
alertDialog.show();
// 显示对话框
}
|
?
12345678910 |
@Override
public boolean onKeyDown(
int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() ==
0
) {
showTips();
return false
;
}
return super
.onKeyDown(keyCode, event);
}
|