• Android异常一、异步任务导致的窗口句柄泄漏问题(转)


    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/7536962

  • 相关阅读:
    windows下用cmd命令netstat查看系统端口使用情况
    linux 运维知识体系
    Oracle中MD5+Base64加密实现
    MySql学习—— 查询性能优化 深入理解MySql如何执行查询
    Mysql集群和主从
    Docker搭建 oracle
    docker容器以ROOT账号登录(获取ROOT权限/ROOT密码)
    一文看懂javaGC
    Docker 国内仓库和镜像
    排序算法___堆排序
  • 原文地址:https://www.cnblogs.com/fighter/p/3180141.html
Copyright © 2020-2023  润新知