Posted on 2010-01-22 00:03
冰浪 閱讀(1086)
評論(0) 編輯 收藏 所屬分類:
Android
android 的 back鍵 返回上一級Activity,當然最終會返回到我們的程序的上一級=>主界面,對于很多程序來說不太友好,那么就讓我們的程序友好一下吧
在我們程序的主Activity中 重寫一下 onKeyDown事件:
- @Override
- public boolean onKeyDown(int keyCode,KeyEvent event) {
-
- if (keyCode == KeyEvent.KEYCODE_BACK) {
-
- this.setConfrimDialogListener(new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- removeDialog(BaseView.DIALOG_YES_NO_MESSAGE);
-
-
-
- android.os.Process.killProcess(android.os.Process.myPid());
- }
- });
- this.setConfrimDialogText(R.string.alert_dialog_exit_confirm);
- this.showDialog(BaseView.DIALOG_YES_NO_MESSAGE);
-
-
-
-
-
- return true;
- } else
- return super.onKeyDown(int keyCode,event);
- }
【轉自:http://wylsx.javaeye.com/blog/511489】