05-05 10:36:41.009: E/WindowManager(4243): Activity com.tao.MyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405241b0 that was originally added here 05-05 10:36:41.009: E/WindowManager(4243): android.view.WindowLeaked: Activity com.tao.MyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405241b0 that was originally added here 05-05 10:36:41.009: E/WindowManager(4243): at android.view.ViewRoot.<init>(ViewRoot.java:265) 05-05 10:36:41.009: E/WindowManager(4243): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 05-05 10:36:41.009: E/WindowManager(4243): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 05-05 10:36:41.009: E/WindowManager(4243): at android.view.Window$LocalWindowManager.addView(Window.java:424) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.Dialog.show(Dialog.java:241) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.ProgressDialog.show(ProgressDialog.java:107) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.ProgressDialog.show(ProgressDialog.java:95) 05-05 10:36:41.009: E/WindowManager(4243): at com.unifable.activity.MySecretaryActivity.onCreate(MySecretaryActivity.java:50) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 05-05 10:36:41.009: E/WindowManager(4243): at android.os.Handler.dispatchMessage(Handler.java:99) 05-05 10:36:41.009: E/WindowManager(4243): at android.os.Looper.loop(Looper.java:130) 05-05 10:36:41.009: E/WindowManager(4243): at android.app.ActivityThread.main(ActivityThread.java:3683) 05-05 10:36:41.009: E/WindowManager(4243): at java.lang.reflect.Method.invokeNative(Native Method) 05-05 10:36:41.009: E/WindowManager(4243): at java.lang.reflect.Method.invoke(Method.java:507) 05-05 10:36:41.009: E/WindowManager(4243): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:906) 05-05 10:36:41.009: E/WindowManager(4243): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:664) 05-05 10:36:41.009: E/WindowManager(4243): at dalvik.system.NativeStart.main(Native Method) 這是在作一個項目的時候遇到的問題:在第一界面的Activity中,爲了不程序假死帶來的糟糕的用戶體驗,採用異步任務AsyncTask來訪問網絡,與服務器進行交互,並用 ProgressDialog控件來告知用戶當前的程序進度。 在網上查了下別人的資料。才終於明白了緣由。 上面的異常的意思是:存在窗口句柄的泄漏,即未能及時的銷燬某個PhoneWindow. 爲何會出現這樣的狀況,由於,在異步任務裏面已經發生了嚴重的錯誤,而致使Activity的強制關閉。Activity強制關閉了,但是ProgressDialog並無dismiss()掉,因此出現了 窗口句柄的泄漏。 並且,更嚴重的是,這個異常會覆蓋咱們在AsyncTask裏面發生的真正異常,這每每會誤導咱們,把過多的精力放在查找所謂的內存泄漏的上面,而不是查找AsyncTask 中出現的錯誤。 參照別人的解決方法: 本解決方法並不能真正的解決問題,可是在必定程度上能夠將真正致使錯誤的異常信息顯露出來。即重寫Activity的onDestory()方法,在該方法中調用dismiss()來解除對ProgressDialog 的引用。
本文轉自http://blog.csdn.net/lonelyroamer/article/details/7536962java