1、退出对话框
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
//退出应用程序
case EXIT_DIALOG:
Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(getResources().getString(R.string.warm_tips));
builder.setMessage(getResources().getString(R.string.app_message));
builder.setPositiveButton(getResources().getString(R.string.confirm),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
return dialog;
}
}
2、Activity的onDestroy
@Override
protected void onDestroy() {
super.onDestroy();
int id = android.os.Process.myPid();
android.os.Process.killProcess(id);
System.exit(0);
}