我有一個Android應用程序..我想whrn用戶點擊退出按鈕它會顯示確認消息,如果他點擊是關閉整個應用程序..的onClick關閉應用程序
嘗試這種代碼,但沒「T工作:
AlertDialog.Builder alertBuilder=new AlertDialog.Builder(AdminEditProfile.this);
alertBuilder.setTitle("Exit");
alertBuilder.setMessage("Are you sure you want to exit from the application?");
alertBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
});
alertBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertBuilder.create().show();
是有辦法做到這一點>
請幫忙,謝謝:)。
張貼您日誌貓錯誤。 – Yugesh 2014-11-25 07:55:04
這是一個**糟糕的做法**強行關閉你的應用程序。改爲使用「主頁」和「後退」按鈕。 – 2014-11-25 07:56:57
這就是爲什麼它是不好的做法:http://android.nextapp.com/site/fx/doc/exit – 2014-11-25 07:58:08