关于WindowManager的一个小问题was originally added here

原创 2015年11月19日 14:42:52


 WindowManager  :悬浮层   它的View显示在整个系统的最顶层,在设置属性后,此View则可以存在手机主窗口上


给windowManager添加overlay这个视图

LayoutInflater inflater = LayoutInflater.from(this);
overlay = (TextView) inflater.inflate(R.layout.overlay, null);
overlay.setVisibility(View.INVISIBLE);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_APPLICATION,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
        PixelFormat.TRANSLUCENT);
windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(overlay, lp);

但是当我关闭此activity时会报如下错误:

   12801-12801/com.wjf.fw.mybus E/WindowManager﹕ Activity com.wjf.fw.mybus.ChangeCityActivity has leaked window android.support.v7.widget.AppCompatTextView{4279d760 I.ED.... ......I. 0,0-130,186} that was originally added here
    android.view.WindowLeaked: Activity com.wjf.fw.mybus.ChangeCityActivity has leaked window android.support.v7.widget.AppCompatTextView{4279d760 I.ED....


虽然此错误不影响应用使用,但毕竟是错误,应该去解决:当销毁activity时应去掉WindowManager的视图

@Override
protected void onDestroy() {
    super.onDestroy();
  windowManager.removeView(overlay);
}




Android问题集锦之二十:Activity has leaked window that was originally added

今天调试程序时log中突然打印这样的错误,但是程序并没有crash,为了不放过一个错误,我决定调查一下。 当时是离开一个activity,然后提示是否退出此界面,接下来就打印此错误: 03-08 18...
  • lincyang
  • lincyang
  • 2014年03月08日 18:02
  • 25519

Dialog使用时has leaked window...that was originally added here错误

错误提示android.view.WindowLeaked: Activity … has leaked window … that was originally added here分析:经常在应用...

has leaked window android.widget.TextView that was originally added 错误

当使用WindowManager 的addView添加界面时, 在释放时,需要调用removeView,否则会出现 has leaked window android.widget.TextVie...
  • leeafu
  • leeafu
  • 2012年11月19日 14:13
  • 4677

Android常见错误之android.widget.LinearLayout@4375f248 that was originally added here

Activity xiaosi.tab.tabActivity has leaked window android.widget.LinearLayout@4375f248 that was orig...
  • SJF0115
  • SJF0115
  • 2012年03月10日 14:11
  • 11843

Android异常一、异步任务导致的窗口句柄泄漏问题

先贴异常: 05-05 10:36:41.009: E/WindowManager(4243): Activity com.tao.MyActivity has leaked window co...

Activity has leaked window that was originally added解决办法

 在使用ProgressDialog的时候,有可能会遇到“Activity has leaked window that was originally added”的错误,原因是ProgresD...

【已解决】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(以解决) 【转】   2011-11-04 14:54:46|  分类: android ...
  • scyatcs
  • scyatcs
  • 2013年07月06日 19:34
  • 2793

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

关于Window和WindowManager的一点愚见(添加,删除,更新)

正文先看看自己要编写一个WindowManager该如何实现。 先看看MainActivity.java @Override protected void onCreate(Bundl...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:关于WindowManager的一个小问题was originally added here
举报原因:
原因补充:

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