关闭

问题:Activity has leaked window that was originally added(以解决)

标签: android2010
430人阅读 评论(0) 收藏 举报
分类:

在编写Android程序的时候,遇到一个隐藏性问题。仔细查看LogCat,错误信息如下:

10-31 13:03:34.549: ERROR/WindowManager(444): Activity com.iqiwu.android.NoticeActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@437d1570 that was originally added here

10-31 13:03:34.549: ERROR/WindowManager(444): android.view.WindowLeaked: Activity com.iqiwu.android.NoticeActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@437d1570 that was originally added here

10-31 13:03:34.549: ERROR/WindowManager(444): at android.view.ViewRoot.<init>(ViewRoot.java:214)

10-31 13:03:34.549: ERROR/WindowManager(444): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)

10-31 13:03:34.549: ERROR/WindowManager(444): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

10-31 13:03:34.549: ERROR/WindowManager(444): at android.view.Window$LocalWindowManager.addView(Window.java:409)

10-31 13:03:34.549: ERROR/WindowManager(444): at android.app.Dialog.show(Dialog.java:238)

10-31 13:03:34.549: ERROR/WindowManager(444): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)

10-31 13:03:34.549: ERROR/WindowManager(444): atcom.iqiwu.android.NoticeActivity.setAlarmNotice(NoticeActivity.java:139)

10-31 13:03:34.549: ERROR/WindowManager(444): atcom.iqiwu.android.NoticeActivity.onCreate(NoticeActivity.java:68)

10-31 13:03:34.549: ERROR/WindowManager(444): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)

……

从错误提示中可以看出,错误产生过程如下:NoticeActivity.onCreate -> NoticeActivity.setAlarmNotice -> AlertDialog$Builder.show,于是发现错误,在关闭Activity的时候,没有关闭AlertDialog!!!

解决方法:

我们知道,在关闭Activity的时候,Activity会调用自己的onPause函数,只要在这里关闭AlertDialog就可以啦!!!至于怎么关闭,其实很简单,调用AlertDialog.dismiss();就可以了。O(∩_∩)o 哈哈。


源地址:http://our2848884.blog.163.com/blog/static/14685483420109319468177/

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:69838次
    • 积分:854
    • 等级:
    • 排名:千里之外
    • 原创:7篇
    • 转载:47篇
    • 译文:1篇
    • 评论:6条
    文章分类