我使用了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并初始化一些其他选项。
答案 0 :(得分:0)
这个针对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);
}