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

转载 2012年03月29日 18:26:11

在编写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/

【已解决】Activity MainActivity has leaked window PhoneWindow$DecorView@ that was originally added here

今天写Sqlite Demo时,发生如下错误: Activity me.dengfengdecao.android.savedatademo.MainActivity has leaked ...

Activity has leaked window that was originally added

Activity has leaked window that was originally added 问题日志相信很多同学都遇到过这个问题window leak。 日志如下 E: androi...
  • ihrthk
  • ihrthk
  • 2017年03月03日 10:10
  • 673

Android排错:has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added

异常场景:经常在应用中需要处理一些耗时的工作,诸如读取大文件、访问网络资源等。为了避免因程序假死而带来的糟糕用户体验,通常我们可以通过线程+Handler或者Android提供的AsyncTask来解...
  • gacmy
  • gacmy
  • 2016年09月24日 10:35
  • 319

Activity has leaked IntentReceiver that was originally registered here. Are you missing a call to u

每次开机的时候应用都会停止运行一次,看log提示以下错误: 09-23 16:56:57.704: E/ActivityThread(938): Activity com.sckj.mo8_lau...

Android异常-Activity has leaked window com.android.internal.policy.impl.PhoneWindow... was originally

异常: : android.view.WindowLeaked: Activity dianshi.matchtrader.activity.MainActivity has leaked windo...

has leaked IntentReceiver ...that was originally registerd here.Are you missing a call to unregister

今天碰到了这个错误:has leaked IntentReceiver ...that was originally registerd here.Are you missing a call to ...

leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405241b0 that was originally ad

先贴异常: [java] view plain copy 05-05 10:36:41.009: E/WindowManager(4243): Ac...

Activity com.avcit.conference.MainActivity has leaked window错误的理解,已解决!

Activity com.avcit.conference.MainActivity has leaked window android.widget.PopupWindow$PopupViewCon...
  • lzan13
  • lzan13
  • 2013年01月10日 10:26
  • 4591

如何解决 It appears that the Web Project,“”,has no Web Root directory setup 问题

如何解决 It appears that the Web Project,“”,has no Web Root directory setup 问题

解决 This Activity already has an action bar supplied by the window decor 错误

报错如下: This Activity already has an action bar supplied by the window decor ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:问题:Activity has leaked window that was originally added(以解决)
举报原因:
原因补充:

(最多只允许输入30个字)