0

我有以下代码来显示一个警报对话框以打开 Locations Service Settings :

alert = new AlertDialog.Builder(context).create();
alert.setTitle("Unable to Retrieve Current Location");
alert.setMessage(" Enable Location Service ?");
alert.setButton(DialogInterface.BUTTON_POSITIVE,"Open Settings", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
        alert.dismiss();
        Intent intent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS);
        context.startActivity(intent);

    }
});
alert.setCancelable(false);
alert.show();

设置正常打开,但是当我按回时,上一个对话框不会被关闭。从设置返回时如何关闭对话框。

4

3 回答 3

0

代替alert.dismiss();

点击事件

尝试finish();//这将完成您的活动

于 2012-12-11T04:52:16.653 回答
0

使用dialog.dismiss();代替alert.dismiss();

于 2012-12-11T04:57:40.430 回答
0

尝试这个:

AlertDialog.Builder alert = new AlertDialog.Builder (context);
alert.setTitle ("Unable to Retrieve Current Location");
alert.setMessage (" Enable Location Service ?");
alert.setButton (DialogInterface.BUTTON_POSITIVE, "Open Settings", 
                 new DialogInterface.OnClickListener() {

  @Override
  public void onClick(DialogInterface dialog, int which) {
    Intent intent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS);
    context.startActivity (intent);
  });

// Create and show the dialog.
alert.create();
alert.show();

主要区别是将create推迟到添加组件之后,调用show,而不是调用dismiss

于 2012-12-11T03:57:59.227 回答