android.view.WindowLeaked: Activity *** has leaked window 处理

05-31 10:46:37.658: ERROR/WindowManager(21946): android.view.WindowLeaked: Activity *** has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2b0c2100 that was originally added here
05-31 10:46:37.658: ERROR/WindowManager(21946):     at android.view.ViewRoot.(ViewRoot.java:264)
05-31 10:46:37.658: ERROR/WindowManager(21946):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
05-31 10:46:37.658: ERROR/WindowManager(21946):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-31 10:46:37.658: ERROR/WindowManager(21946):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-31 10:46:37.658: ERROR/WindowManager(21946):     at android.app.Dialog.show(Dialog.java:241)
05-31 10:46:37.658: ERROR/WindowManager(21946):     at android.app.AlertDialog$Builder.show(AlertDialog.java:816)
05-31 10:46:37.658: ERROR/WindowManager(21946):     at

 

该错误是由于在Activity中创建并显示了Alertdialog,但并未使用Activity提供的showDialog()方法,因此导致在Activity被结束后,Alertdialog所引用的context为空。解决办法为,1,将dialog采用oncreateDialog的方式创建,交由系统维护。

2.在onDestroy()方法中将该alertdialog dismiss掉。

 

你可能感兴趣的:(Android,Java)