[Android] LINT: use static handler

Sébastien Toque git at videolan.org
Sat May 25 16:33:45 CEST 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sat May 25 14:03:44 2013 +0200| [3834fb80b63ccb397d240599100b5cf8e6bab70e] | committer: Sébastien Toque

LINT: use static handler

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

 vlc-android/src/org/videolan/vlc/MediaLibrary.java |   29 +++++++++++---------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 5e28455..3c0137a 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -347,7 +347,7 @@ public class MediaLibrary {
                 if (mRestart) {
                     Log.d(TAG, "Restarting scan");
                     mRestart = false;
-                    restartHandler.sendEmptyMessage(1);
+                    restartHandler.sendEmptyMessageDelayed(1, 200);
                 } else {
                     mRestartContext = null;
                     mContext = null;
@@ -356,20 +356,23 @@ public class MediaLibrary {
         }
     };
 
-    private Handler restartHandler = new Handler() {
+    private Handler restartHandler = new RestartHandler(this);
+
+    private static class RestartHandler extends WeakHandler<MediaLibrary> {
+        public RestartHandler(MediaLibrary owner) {
+            super(owner);
+        }
+
         @Override
-        public void handleMessage(final Message msgs) {
-            restartHandler.postDelayed(new Runnable() {
-                @Override
-                public void run() {
-                    if (mRestartContext != null)
-                        loadMediaItems(mRestartContext);
-                    else
-                        Log.e(TAG, "Context lost in a black hole");
-                }
-            }, 200);
+        public void handleMessage(Message msg) {
+            MediaLibrary owner = getOwner();
+            if(owner == null) return;
+            if (owner.mRestartContext != null)
+                owner.loadMediaItems(owner.mRestartContext);
+            else
+                Log.e(TAG, "Context lost in a black hole");
         }
-    };
+    }
 
     /**
      * Filters all irrelevant files



More information about the Android mailing list