8

我收到此错误:已泄漏窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0 最初添加在这里我在模拟器中有网络连接,通过打开网站检查浏览器。

我在 processdialog 行遇到错误。

@SuppressLint("NewApi")
private class TheTask extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        dialog = ProgressDialog.show(Register.this, "",
                "Registering... Please wait...", true);
    }

    @Override
    protected Void doInBackground(Void... params) {

        request = new SoapObject(NAMESPACE, METHOD_NAME);

        name = new PropertyInfo();
        name.setName("Name");
        name.setValue(Name);
        name.setType(String.class);
        request.addProperty(name);

        SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envp.dotNet = true;
        envp.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            androidHttpTransport.call(SOAP_ACTION, envp);
            SoapPrimitive response = (SoapPrimitive) envp.getResponse();
            Response = response.toString();

        } catch (Exception e) {
            textValidation.setText(e.toString());
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        if (dialog != null) {
            dialog.dismiss();
            dialog = null;
        }
        }
    }
}
4

2 回答 2

51

如果您的活动已被销毁但您的对话框仍在显示,则会发生此错误。所以你已经在你的活动中添加了这些代码onDestroy()

@Override
public void onDestroy() {
    super.onDestroy();
    if (dialog != null) {
        dialog.dismiss();
        dialog = null;
    }
}
于 2013-05-27T07:59:13.557 回答
2

可能是因为你在写

textValidation.setText(e.toString());

函数内部,

doInBackground()

这是更新 android 在 doInBackground() 方法中允许的 UI。所以如果你把这条线放进去

后执行()

那么这个问题就会得到解决。

于 2013-11-26T05:48:26.323 回答