[Android] Fix potential handler leak

Geoffrey Métais git at videolan.org
Thu Oct 22 18:25:23 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 22 18:11:11 2015 +0200| [b105efb65736f2100eb848aa218a51816717837e] | committer: Geoffrey Métais

Fix potential handler leak

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=b105efb65736f2100eb848aa218a51816717837e
---

 .../src/org/videolan/vlc/widget/OnRepeatListener.java |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/widget/OnRepeatListener.java b/vlc-android/src/org/videolan/vlc/widget/OnRepeatListener.java
index 474291a..9053101 100644
--- a/vlc-android/src/org/videolan/vlc/widget/OnRepeatListener.java
+++ b/vlc-android/src/org/videolan/vlc/widget/OnRepeatListener.java
@@ -28,6 +28,8 @@ import android.os.Message;
 import android.view.MotionEvent;
 import android.view.View;
 
+import org.videolan.vlc.util.WeakHandler;
+
 public class OnRepeatListener implements View.OnTouchListener {
 
     private static final int ACTION_ONCLICK = 0;
@@ -84,14 +86,21 @@ public class OnRepeatListener implements View.OnTouchListener {
         return false;
     }
 
-    private Handler mHandler = new Handler() {
+    private Handler mHandler = new OnRepeatHandler(this);
+
+    private static class OnRepeatHandler extends WeakHandler<OnRepeatListener> {
+
+        public OnRepeatHandler(OnRepeatListener owner) {
+            super(owner);
+        }
+
         @Override
         public void handleMessage(Message msg) {
             switch (msg.what){
                 case ACTION_ONCLICK:
-                    sendEmptyMessageDelayed(ACTION_ONCLICK, mNormalInterval);
-                    mClickListener.onClick(downView);
+                    sendEmptyMessageDelayed(ACTION_ONCLICK, getOwner().mNormalInterval);
+                    getOwner().mClickListener.onClick(getOwner().downView);
             }
         }
-    };
+    }
 }



More information about the Android mailing list