//监听返回键
public void onBackPressed(){
confirmExit();
}
//确认退出程序对话
private void confirmExit()
{
//确认退出程序
new AlertDialog.Builder(this).setTitle(R.string.confirm_exit)
.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//点击'yes'后执行退出操作
MainActivity.this.finish();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//取消操作
}
}).show();
}