虽然是小问题一个,但也困扰了我一段时间,现在记下来,给自己做个备忘,也可以给其他人一个参考
view plaincopy to clipboardprint?
01-08 01:49:27.874: ERROR/WindowManager(473): Activity com.photos.MainActivity has leaked window android.widget.ImageButton@43e40d10 that was originally added here
01-08 01:49:27.874: ERROR/WindowManager(473): android.view.WindowLeaked: Activity com.photos.MainActivity has leaked window android.widget.ImageButton@43e40d10 that was originally added here
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.ViewRoot.<init>(ViewRoot.java:247)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.Window$LocalWindowManager.addView(Window.java:424)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.widget.PopupWindow.invokePopup(PopupWindow.java:828)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:688)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity.showCommonPopup(MainActivity.java:256)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity.access$3(MainActivity.java:255)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity$2.handleMessage(MainActivity.java:88)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.os.Looper.loop(Looper.java:123)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-08 01:49:27.874: ERROR/WindowManager(473): at java.lang.reflect.Method.invokeNative(Native Method)
01-08 01:49:27.874: ERROR/WindowManager(473): at java.lang.reflect.Method.invoke(Method.java:521)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-08 01:49:27.874: ERROR/WindowManager(473): at dalvik.system.NativeStart.main(Native Method)
01-08 01:49:27.874: ERROR/WindowManager(473): Activity com.photos.MainActivity has leaked window android.widget.ImageButton@43e40d10 that was originally added here
01-08 01:49:27.874: ERROR/WindowManager(473): android.view.WindowLeaked: Activity com.photos.MainActivity has leaked window android.widget.ImageButton@43e40d10 that was originally added here
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.ViewRoot.<init>(ViewRoot.java:247)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.Window$LocalWindowManager.addView(Window.java:424)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.widget.PopupWindow.invokePopup(PopupWindow.java:828)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:688)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity.showCommonPopup(MainActivity.java:256)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity.access$3(MainActivity.java:255)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity$2.handleMessage(MainActivity.java:88)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.os.Looper.loop(Looper.java:123)
01-08 01:49:27.874: ERROR/WindowManager(473): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-08 01:49:27.874: ERROR/WindowManager(473): at java.lang.reflect.Method.invokeNative(Native Method)
01-08 01:49:27.874: ERROR/WindowManager(473): at java.lang.reflect.Method.invoke(Method.java:521)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-08 01:49:27.874: ERROR/WindowManager(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-08 01:49:27.874: ERROR/WindowManager(473): at dalvik.system.NativeStart.main(Native Method)
--------------------------------------------------------------------------------
按字面了解,Window Leaked大概就是说一个窗体泄漏了,也就是我们常说的内存泄漏,为什么窗体会泄漏呢?
产生原因:
我们知道Android的每一个Activity都有个WindowManager窗体管理器,同样,构建在某个Activity之上的对话框、PopupWindow也有相应的WindowManager窗体管理器。因为对话框、PopupWindown不能脱离Activity而单独存在着,所以当某个Dialog或者某个PopupWindow正在显示的时候我们去finish()了承载该Dialog(或PopupWindow)的Activity时,就会抛Window Leaked异常了,因为这个Dialog(或PopupWindow)的WindowManager已经没有谁可以附属了,所以它的窗体管理器已经泄漏了。
解决方法:
关闭(finish)某个Activity前,要确保附属在上面的Dialog或PopupWindow已经关闭(dismiss)了。
分享到:
相关推荐
Android 中 android.view.WindowLeaked的解决办法 按字面了解,Window Leaked大概就是说一个窗体泄漏了,也就是我们常说的内存泄漏,为什么窗体会泄漏呢? 产生原因: 我们知道Android的每一个Activity都有个...
在Android开发中,根View(Root View)是布局文件中最高层次的视图容器,它包含并管理着应用界面中的所有子视图。根View通常是LinearLayout、RelativeLayout、FrameLayout等布局组件,它决定了子视图的排列方式和...
基于android的计算器代码 ...import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.GridLayout; import android.widget.TextView;
标题中的“android viewpager android-support-v4.jar”指的是Android平台上的一个关键组件——ViewPager,以及它依赖的Android Support Library v4。ViewPager是Android SDK中用于实现页面滑动效果的控件,常见于...
ctrip.android.view_1608.apk
android system webview 适配系统>=5.0
通过深入研究`android.jar`源码,开发者不仅可以更好地理解和利用Android API,还能提高解决问题的能力,为打造高效、稳定、安全的Android应用打下坚实基础。无论是初学者还是资深开发者,都应该对这个宝藏库进行...
compile 'net.wujingchao.android.view:simple-tag-imageview:1.0.1' Maven <!-- you should configure jcenter repository--> net.wujingchao.android.view simple-tag-imageview 1.0.1 aar Developed ...
解决Eclipse 无NDK 选项问题,将com.android.ide.eclipse.traceview_23.0.2.1259578.jar 包放到Eclipse ->plugins文件夹下!
import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.animation.DecelerateInterpolator; import android.widget.AbsListView; import android.widget.AbsListView.OnScrollListener...
import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; public class MyToast { public static void ...
import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ListView; import android....
安卓开发-Android 主流的图片浏览的全屏缩放效果SmoothImageDemo软件源码: import java.io.File; import java.util....import android.view.ViewGroup; import android.widget.BaseAdapter; import android.wi
implementation 'com.android.support:design:版本号' } ``` 记得替换`版本号`为当前支持库的最新版本。 2. **添加TabLayout到布局** 在XML布局文件中,使用`TabLayout`标签来创建一个TabLayout实例: ```xml...
第3步:新建一个View命名为MainView.java就是我们Activity现实的View.代码如下: package com.tutor.application; import android.app.Activity; import android.content.Context; import android.util....
ceated : 2010/05/18 maker : hojun, baek ...import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.SimpleAdapter;
这是最新版的android-support-v4.jar,大小1MB多,比其它那种几百K的要大,因为这是最新的android-support-v4.jar,有最新的android.support.v4.view.animation类,现在是2015年10月,这是截至目前最新的jar包
android;多媒体开发;android应用开发揭秘。 import java.io.File; import java.io.FilenameFilter; import java.io.IOException;...import java.util.ArrayList;...import android.app....import android.view.SubMenu
功能如标题所示,简单的android的3秒倒计时关闭界面或点击关闭,如果3秒内点击就不会再开启自动关闭。看图说话,代码简单,...import android.view.View; import android.widget.Button; import android.widget.ImageV