如何阻止alertdialog自动消失

Ani*_*ish 3 android android-dialog

以下是我的代码,用于在GPS关闭时提醒用户.在这里,我的用户必须单击其中一个选项并进一步移动.但是,如果用户点击此警报以外的其他屏幕,此警报将消失.如何阻止此警报对话框自动消失.请帮忙

Builder bd = new AlertDialog.Builder(myTest.this);
    bd.setTitle("Alert");       
    bd.setMessage("GPS is disabled. Do you want to");
    bd.setNegativeButton("Enable GPS", new DialogInterface.OnClickListener() {              
                public void onClick(DialogInterface dialog, int which) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }});            
            bd.setPositiveButton("Close App", new DialogInterface.OnClickListener() {               
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
                });
    bd.show();  
Run Code Online (Sandbox Code Playgroud)

Gab*_*han 6

使用bd.setCancelable(false).这将使它只能通过按下按钮消失.