app突然抛出java.lang.IllegalArgumentException: View not attached to window manager 的异常,查看了一些资料,才解决了此bug。
推荐关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析 这篇文章,分析的比较彻底。
overflow上的http://stackoverflow.com/questions/22924825/view-not-attached-to-window-manager-crash这个提问,也有很好的解释。
复制下回答者的解释:
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
.
How to fix it:
- 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.
最终的解决办法是直接在activity的destroy方法里把dialog给dismiss了