gpt4 book ai didi

android - PullToRefresh(chrisbanes lib) 窗口泄漏

转载 作者:太空狗 更新时间:2023-10-29 15:04:17 25 4
gpt4 key购买 nike

我使用了 PullToRefresh chrisBanes 库 https://github.com/chrisbanes/Android-PullToRefresh .我扩展了 PullToRefreshAttacher,因为我需要特定的行为。一切正常,当 Activity 恢复时我有下一个堆栈跟踪错误,但 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.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);
}

关于android - PullToRefresh(chrisbanes lib) 窗口泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23388106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com