以下是我的AlertDialog的代碼,取消AlertDialog在活動的onPause方法在Android的
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle("GPS settings");
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
@Override
protected void onPause() {
super.onPause();
// I want dialog to be dismissed here
}
其工作正常,但我想要的是關閉該對話框中的活動的onPause方法,
我如何能實現它呢?
使用dialog.dismiss()函數... – 2014-11-21 06:34:03