【问题标题】:PullToRefresh(chrisbanes lib) window leakedPullToRefresh(chrisbanes lib) 窗口泄露
【发布时间】:2014-06-16 18:35:48
【问题描述】:

我使用了 PullToRefresh chrisBanes lib https://github.com/chrisbanes/Android-PullToRefresh 。我扩展了 PullToRefreshAttacher,因为我需要特定的行为。一切正常,当活动恢复时我有下一个堆栈跟踪错误,但 pullToRefresh 仍然可以正常工作(它只在日志中):

23732-23732/com.prinum.android.mb E/WindowManager﹕ android.view.WindowLeaked: Activity  has leaked window android.widget.RelativeLayout{42b28870 I.E..... ......ID 0,0-1080,156} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:348)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
        at uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.addHeaderViewToActivity(PullToRefreshAttacher.java:616)
        at uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacherEx.addHeaderViewToActivity(PullToRefreshAttacherEx.java:47)
        at uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher$1.run(PullToRefreshAttacher.java:128)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

我尝试使用标准的 PullToRefresh,但遇到了同样的问题。 但如果我像这样初始化 pullToRefresh:

ActionBarPullToRefresh.from(this)
        // Mark All Children as pullable
        .allChildrenArePullable()
        // Set a OnRefreshListener
        .listener(...)
        // Finally commit the setup to our PullToRefreshLayout
        .setup(mPullToRefreshLayout);

销毁和恢复后,没有出现错误堆栈跟踪。 setup() 方法创建 PullToRefreshAttacher 并初始化一些附加选项。

【问题讨论】:

  • 嗯。我使用完全相同的ActionBarPullToRefresh.from 调用,但我仍然得到WindowLeaked 堆栈跟踪。 ://

标签: android pull-to-refresh


【解决方案1】:

这个针对ActionBarPullToRefresh.java@5d84f1b 的补丁为我消除了堆栈跟踪:

@@ -117,13 +117,13 @@ public class ActionBarPullToRefresh {
             }
         }

-        private static void insertLayoutIntoViewGroup(ViewGroup viewGroup,
+        private void insertLayoutIntoViewGroup(ViewGroup viewGroup,
                 PullToRefreshLayout pullToRefreshLayout) {
             // Move all children to PullToRefreshLayout. This code looks a bit silly but the child
             // indices change every time we remove a View (so we can't just iterate through)
             View child = viewGroup.getChildAt(0);
             while (child != null) {
-                viewGroup.removeViewAt(0);
+                mActivity.getWindowManager().removeViewImmediate(viewGroup.getChildAt(0));
                 pullToRefreshLayout.addView(child);
                 child = viewGroup.getChildAt(0);
             }

【讨论】:

  • 此更改一定没有进入0.9.9
  • 我在头部使用了 github 和 it's not there,所以我根本不知道它曾经进入过。 (我一开始也链接到了错误的文件。我已经修复了。)
  • 您正在修改的方法(私有静态 void insertLayoutIntoViewGroup)是静态的。我不确定它是如何编译的,因为 mActivity 是一个类成员,你不应该能够访问它。
  • 感谢@PhilYoussef,很好。我还将方法更改为非静态的,但这并没有进入补丁。我已经更新了。
猜你喜欢
  • 1970-01-01
  • 2013-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-16
  • 2016-06-26
相关资源
最近更新 更多