Dialog显示引起的问题 Activity has leaked window DecorView@5704632[] that was originally added here

简介: Dialog显示引起的问题 Activity has leaked window DecorView@5704632[] that was originally added here

dialog显示引起的界面无法打开的问题,报错信息如下:

  1. 03-08 18:02:48.521: E/WindowManager(6340): Activity com.linc.megatron.activity.ExamActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40568ea8 that was originally added here  
  2. 03-08 18:02:48.521: E/WindowManager(6340): android.view.WindowLeaked: Activity com.linc.megatron.activity.ExamActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40568ea8 that was originally added here  
  3. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.(ViewRoot.java:264)  
  4. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)  
  5. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)  
  6. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.Window$LocalWindowManager.addView(Window.java:424)  
  7. 03-08 18:02:48.521: E/WindowManager(6340):  at android.app.Dialog.show(Dialog.java:241)  
  8. 03-08 18:02:48.521: E/WindowManager(6340):  at com.linc.megatron.base.BackKeyActivity.showDialog(BackKeyActivity.java:76)  
  9. 03-08 18:02:48.521: E/WindowManager(6340):  at com.linc.megatron.base.BackKeyActivity.onKeyDown(BackKeyActivity.java:62)  
  10. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.KeyEvent.dispatch(KeyEvent.java:1256)  
  11. 03-08 18:02:48.521: E/WindowManager(6340):  at android.app.Activity.dispatchKeyEvent(Activity.java:2078)  
  12. 03-08 18:02:48.521: E/WindowManager(6340):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1709)  
  13. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2628)  
  14. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2603)  
  15. 03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1875)  
  16. 03-08 18:02:48.521: E/WindowManager(6340):  at android.os.Handler.dispatchMessage(Handler.java:99)  
  17. 03-08 18:02:48.521: E/WindowManager(6340):  at android.os.Looper.loop(Looper.java:123)  
  18. 03-08 18:02:48.521: E/WindowManager(6340):  at android.app.ActivityThread.main(ActivityThread.java:3687)  
  19. 03-08 18:02:48.521: E/WindowManager(6340):  at java.lang.reflect.Method.invokeNative(Native Method)  
  20. 03-08 18:02:48.521: E/WindowManager(6340):  at java.lang.reflect.Method.invoke(Method.java:507)  
  21. 03-08 18:02:48.521: E/WindowManager(6340):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)  
  22. 03-08 18:02:48.521: E/WindowManager(6340):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)  
  23. 03-08 18:02:48.521: E/WindowManager(6340):  at dalvik.system.NativeStart.main(Native Method)

显然,我用Dialog确认是否退出,但是activity销毁后并没有处理Dialog的退出。

解决办法:

只需要在activity销毁时关闭Dialog就好。

[java] view plaincopy

  1. @Override  
  2. protected void onDestroy() {  
  3.    if(mDialog != null) {  
  4.        mDialog.dismiss();  
  5.    }  
  6.    super.onDestroy();  
  7. }  
相关文章
|
7月前
|
Java Android开发 Kotlin
Android Dialog 弹出时,隐藏 navigation bar
Android Dialog 弹出时,隐藏 navigation bar
131 1
|
Android开发
Android | View & Fragment & Window 的 getContext() 一定返回 Activity 吗?
Android | View & Fragment & Window 的 getContext() 一定返回 Activity 吗?
168 0
Android | View & Fragment & Window 的 getContext() 一定返回 Activity 吗?
|
存储 缓存 安全
为什么不能使用 Application Context 显示 Dialog?
为什么不能使用 Application Context 显示 Dialog?
为什么不能使用 Application Context 显示 Dialog?
|
Java
Preference跳转activity出错Unable to find explicit activity class
使用Preference可以非常方便的实现类似设置页面这样的菜单布局,甚至可以不需写java代码。那么可以在Preference中直接添加页面跳转么?其实非常简单,在Preference添加intent标签即可
530 0
|
Kotlin
【错误记录】布局组件加载错误 ( Attempt to invoke virtual method ‘xxx$Callback android.view.Window.getCallback()‘ )
【错误记录】布局组件加载错误 ( Attempt to invoke virtual method ‘xxx$Callback android.view.Window.getCallback()‘ )
318 0
Fragment Or DialogFragment Can not perform this action after onSaveInstanceState
转载自Fragment Or DialogFragment Can not perform this action after onSaveInstanceState 表现 可会造成app崩溃掉,具体日志如下: 异常如下: java.
2727 0
|
缓存 前端开发 Java
Activity显示到Window的过程
写在前面的话 今天看到一个新闻,关于虾米音乐的程序员写的注释。 好像图都绿了,突然间想起在我曾经老大的影响下,我的Log输出已经变成了fxxk。
998 0