问题
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:
The error will happen if you're trying to show a
Dialog
after you've exited anActivity
.Also, if an unhandled Exception was thrown in your
AsyncTask
, which would cause theActivity
to shutdown, then an open progress dialog will cause theException
.
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