打开系统位置设置后,android 对话框不会关闭

标签 android dialog settings

我有一个对话框,提示用户启用 GPS 位置(如果未启用)。

打开设置、用户启用 GPS 并按位置设置屏幕上的后退按钮后,他们将返回应用程序,但对话框仍然可见。

这是单击的按钮的代码。

    // On pressing Settings button
    alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mContext.startActivity(intent);
            dialog.dismiss();
        }

    });

我的问题是为什么dialog.dismiss()不关闭对话框,我也尝试过dialog.cancel(),结果相同。打开设置屏幕后我应该做什么?

谢谢

最佳答案

我的Activity中有这个代码:

private void showLocationDisabledInfo() {
    final Context c = this;
    AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setMessage("TEST");
    builder.setPositiveButton("OK", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            c.startActivity(intent);
        }
    });
    builder.setNeutralButton(R.string.cancel, null);
    builder.create().show();
}

无论我单击哪个按钮,它都会自动关闭对话框。它来 self 的应用程序,并在具有 API 810 的设备以及运行 API 17 的模拟器上进行了测试。我们的代码之间唯一的区别(可能)是 mContext 的值。请提供负责设置对话框以及您在其中看到所描述行为的环境的完整代码。

关于打开系统位置设置后,android 对话框不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14007966/

相关文章:

android - ListView 中的多个文件下载管理器 +progress/pause/resume android

c# - 创建新的设置实例

iphone - 隐藏设置包中的首选项

java - postData 无法解析为类型

android - 如何获取Android软键盘高度?

android - 在 S3 服务器上并行上传图片

wpf - 仅在 WPF 中的 ShowDialog() 之后设置 DialogResult

delphi - 如何使用Delphi标准确认对话框但带有复选框 "Don'不要再问我“?

java - 将数组对象中的信息打印到单独的字段中

wordpress - 在 WooCommerce 3.3 中更改产品缩略图大小