Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0 that was originally added here
Asked Answered
A

2

8

I am getting this error : has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0 that was originally added here I have net connection in emulator, check it out browser by opening websites.

I am getting error at the line of 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;
        }
        }
    }
}
Auroraauroral answered 27/5, 2013 at 7:56 Comment(4)
possible duplicate of Android: activity has leaked window due to progress dialog?Sterilant
please change Void to voidDear
probably App is crashing be because you are trying to update UI element from doInBackground so use onPostExecute for updating ui elements instead of doInBackgroundSubinfeudation
yeah, rite.. it was showing bcz of UI element from doInBackground... thank you so much.Auroraauroral
G
51

This error will happen if your activity has been destroyed but you dialog is still showing. So You have added these code in your activity's onDestroy()

@Override
public void onDestroy() {
    super.onDestroy();
    if (dialog != null) {
        dialog.dismiss();
        dialog = null;
    }
}
Glycerinate answered 27/5, 2013 at 7:59 Comment(6)
App was crashing i was trying to update UI element from doInBackground.Auroraauroral
U cannot change UI from another background thread. Try changing from postExecuteHorseplay
rite, vivek. But then why it is working when I am not sending data to my computer local server. I have changed it to main server of my company and that time only, I got this error.Auroraauroral
super.onDestroy() should be called first.Worldly
Thank Johan S, I confirm that you are right :). I have misunderstood it for a very long time.Glycerinate
LOL i am impressed you know why .. I didt declare dialog and when I i hve used this on destroy .. my issue got fixed lol :) thanksRewrite
E
2

Possibly Its Because of you are writing

textValidation.setText(e.toString());

inside the function,

doInBackground()

which is updating UI which is allowed by android in doInBackground() method. So somehow if you put this line in

postExecute()

then this problem will get resolved.

Elsie answered 26/11, 2013 at 5:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.