search

Home  >  Q&A  >  body text

android - 运用WindowManager添加了一个Window,在销毁activity时总是报"has leaked window"

代码大概如下

windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(linearLayout, layoutParams);
protected void onDestroy() {
    windowManager.removeView(linearLayout);
    super.onDestroy();
}

我在activity onDestory()时调用了windowManager的removeView()方法也不行,还是会报相同的错误。难道
说removeView()方法调用后创建的Window还会存在么?应该如何彻底删除这个Window。

大家讲道理大家讲道理2772 days ago446

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 17:35:47

    I answered it myself, just use the removeViewImmediate() method instead of the removeView() method

    reply
    0
  • Cancelreply