Activity has leaked window?

你。 提交于 2020-01-07 03:14:05

问题


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().



来源:https://stackoverflow.com/questions/24781454/activity-has-leaked-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!