主界面监听返回键,退出程序

/**
 * 通用退出程序的提示框
 * 
 * @param context
 */
public static void exit_dialog(Context context) {
	AlertDialog.Builder builder = new Builder(context);
	builder.setMessage("确定要退出吗?");
	builder.setTitle("提示");
	builder.setIcon(android.R.drawable.ic_dialog_alert);
	builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			dialog.dismiss();
			MyApplication.getInstance().exit();
		}
	});


	builder.setNegativeButton("取消",
			new android.content.DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});


	builder.create().show();
}

其中MyApplication.getInstance().exit();的MyApplication类参照MyApplication.java

你可能感兴趣的:(android,android,android,提示框,退出程序)