How to reproduce the bug:post
- Enable this option on your device:
Settings -> Developer Options -> Don't keep Activities
. - Press Home button while the
AsyncTask
is executing and theProgressDialog
is showing.
The Android OS will destroy an activity as soon as it is hidden. When onPostExecute
is called the Activity
will be in "finishing" state and the ProgressDialog
will be not attached to Activity
.this
How to fix it:url
- Check for the activity state in your
onPostExecute
method. - Dismiss the
ProgressDialog
inonDestroy
method. Otherwise,android.view.WindowLeaked
exception will be thrown. This exception usually comes from dialogs that are still active when the activity is finishing.