[Android] runOnMainThread util method

Geoffrey Métais git at videolan.org
Tue Jan 10 10:51:10 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  9 18:35:11 2017 +0100| [5fad7f8495a6748186767f3f3550c8f895885fed] | committer: Geoffrey Métais

runOnMainThread util method

> https://code.videolan.org/videolan/vlc-android/commit/5fad7f8495a6748186767f3f3550c8f895885fed
---

 vlc-android/src/org/videolan/vlc/VLCApplication.java | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index a67aeac..0cf527e 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -25,6 +25,8 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.os.Handler;
+import android.os.Looper;
 import android.os.Process;
 import android.preference.PreferenceManager;
 import android.support.v4.app.DialogFragment;
@@ -77,6 +79,7 @@ public class VLCApplication extends Application {
             return thread;
         }
     };
+    private Handler mHandler = new Handler(Looper.getMainLooper());
 
     private static int sDialogCounter = 0;
 
@@ -179,6 +182,10 @@ public class VLCApplication extends Application {
         instance.mThreadPool.execute(runnable);
     }
 
+    public static void runOnMainThread(Runnable runnable) {
+        instance.mHandler.post(runnable);
+    }
+
     public static boolean removeTask(Runnable runnable) {
         return instance.mThreadPool.remove(runnable);
     }



More information about the Android mailing list