Activity has leaked window?

2019-09-13 02:01发布

问题:

I am having one java class in that class as soon some one purchases our application then it will start downloading and progress dialog has to appear instead it goes to some other page and when i come out of the application and when i restart then it starts downloading. Please Help me out from this mess...

Thank you

回答1:

Check the condition for dialog, before showing.

Like this

if(pDialog!=null)
{
  if(!pDialog.isShowing())
{
pDialog.show();
}
}

and also while removing the dialog in onPostexecute() check for null.

if Still not works just remove the pDialog and try once with your code.



回答2:

Two causes for your error happen:

  1. The error will happen if you're trying to show a Dialog after you've exited an Activity.

  2. Also, if an unhandled Exception was thrown in your AsyncTask, which would cause the Activity to shutdown, then an open progress dialog will cause the Exception.

According to the Log you've posted, the error happens after you call pDialog.show() which might be the 1st cause I've mentioned before.

Also you are calling finish() in many parts of your code, maybe one of these calls are making your Activity to stop and leaking your Dialog.

You must check which one of them is finishing your Activity before you show the Dialog. A good solution is to dismiss the Dialog (if it's showing) before calling finish().