本文介绍了无法解雇AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨需要从服务显示AlertDialog。

这是我的实现。

我添加的权限:

 <使用许可权的android:NAME =android.permission.SYSTEM_ALERT_WINDOW/>

但我不能关闭该对话框!

我点击确定按钮,但ID不会消失!

和所有的系统冻结该对话框!

请帮助!

 公共类CreditcheckService扩展IntentService {
AlertDialog对话框;
公共CreditcheckService(){
    超级(CreditcheckService);
}@覆盖
保护无效onHandleIntent(意向意图){
    AlertDialog.Builder建设者=新AlertDialog.Builder(
            getApplicationContext());    builder.setMessage(R.string.please_connect).setTitle(
            R.string.unable_to);
    builder.setPositiveButton(R.string.okay_action,
            新OnClickListener(){
        @覆盖
        公共无效的onClick(DialogInterface阿根廷,
                其中INT){dialog.cancel();
        }
    });
    对话框= builder.create();
    dialog.getWindow()的setType(
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    dialog.show();
}


解决方案

试试这个:

  AlertDialog.Builder建设者=新AlertDialog.Builder(本);
    builder.setMessage()
            .setCancelable(假)
            .setPositiveButton(是,NULL);
    AlertDialog警报= builder.create();
    alert.show();
}

Hi need to show a AlertDialog from a Service.

This is my implementation.

I added the permission:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

But I am not able to dismiss the dialog!!!

I click the OK button but id does not go away!!!

And all the system freezes on that dialog !!!

Please help!!!

public class CreditcheckService extends IntentService {
AlertDialog dialog;
public CreditcheckService() {
    super("CreditcheckService");
}

@Override
protected void onHandleIntent(Intent intent) {
    AlertDialog.Builder builder = new AlertDialog.Builder(
            getApplicationContext());

    builder.setMessage(R.string.please_connect).setTitle(
            R.string.unable_to);
    builder.setPositiveButton(R.string.okay_action,
            new OnClickListener() {
        @Override
        public void onClick(DialogInterface arg,
                int which) {dialog.cancel();
        }
    });
    dialog= builder.create(); 
    dialog.getWindow().setType(
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    dialog.show();
}
解决方案

try this:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("")
            .setCancelable(false)
            .setPositiveButton("Yes",null);
    AlertDialog alert = builder.create();
    alert.show();   
}

这篇关于无法解雇AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 18:27