3

I used PullToRefresh chrisBanes lib https://github.com/chrisbanes/Android-PullToRefresh . I extends PullToRefreshAttacher, cause I need specific behaviour. All works normal,when activity restored I had next stacktrace errors, but pullToRefresh still works fine (it's only in logs):

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)

I tried to use standard PullToRefresh and I faced with the same problem. But if I init pullToRefresh like:

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

After destroyed and restored, error stacktrace not appeared. setup() method create PullToRefreshAttacher and init some additional options.

user3134124
  • 387
  • 4
  • 16
  • 1
    huh. i use the exact same `ActionBarPullToRefresh.from` call, but i still get the `WindowLeaked` stack traces. :/ – ryan May 02 '14 at 18:28

1 Answers1

0

this patch against ActionBarPullToRefresh.java@5d84f1b got rid of the stack traces for me:

@@ -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);
             }
ryan
  • 2,687
  • 1
  • 29
  • 38
  • This change must not have made it into `0.9.9`? – theblang May 12 '14 at 18:58
  • i used github at head, and [it's not there](https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/library/src/main/java/uk/co/senab/actionbarpulltorefresh/library/ActionBarPullToRefresh.java#L126), so i don't know that it ever went in at all. (i also linked to the wrong file above at first. i've fixed that.) – ryan May 12 '14 at 19:41
  • The method you're modifying (private static void insertLayoutIntoViewGroup) is static. I'm not sure how this compiles since mActivity is a class member and you shouldn't be able to access it. – PhilYoussef Aug 27 '14 at 03:27
  • thanks @PhilYoussef, good catch. i'd also changed the method to be non-static, but that didn't make it into the patch. i've updated it. – ryan Aug 27 '14 at 22:16