Activity has leaked window that was originally added

I triggered this error by mistakenly calling hide() instead of dismiss() on an AlertDialog.


If you are using AsyncTask, probably that log message can be deceptive. If you look up in your log, you might find another error, probably one in your doInBackground() method of your AsyncTask, that is making your current Activity to blow up, and thus once the AsyncTask comes back.. well, you know the rest. Some other users already explained that here :-)


The solution is to call dismiss() on the Dialog you created in viewP.java:183 before exiting the Activity, e.g. in onPause(). All Windows&Dialogs should be closed before leaving an Activity.


You're trying to show a Dialog after you've exited an Activity.

[EDIT]

This question is one of the top search on google for android developer, therefore Adding few important points from comments, which might be more helpful for future investigator without going in depth of comment conversation.

Answer 1 :

You're trying to show a Dialog after you've exited an Activity.

Answer 2

This error can be a little misleading in some circumstances (although the answer is still completely accurate) - i.e. in my case an unhandled Exception was thrown in an AsyncTask, which caused the Activity to shutdown, then an open progressdialog caused this Exception.. so the 'real' exception was a little earlier in the log

Answer 3

Call dismiss() on the Dialog instance you created before exiting your Activity, e.g. in onPause() or onDestroy()