[Android] We do not need app instance to start jobs

Geoffrey Métais git at videolan.org
Mon Feb 19 10:31:21 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 19 10:30:40 2018 +0100| [162f0a0badf2dae322a86ed252c08cce5a84e83a] | committer: Geoffrey Métais

We do not need app instance to start jobs

> https://code.videolan.org/videolan/vlc-android/commit/162f0a0badf2dae322a86ed252c08cce5a84e83a
---

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

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 004fed61b..f1126ec6a 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -71,7 +71,7 @@ public class VLCApplication extends Application {
     private static SimpleArrayMap<String, WeakReference<Object>> sDataMap = new SimpleArrayMap<>();
 
     /* Up to 2 threads maximum, inactive threads are killed after 2 seconds */
-    private final int maxThreads = Math.max(AndroidUtil.isJellyBeanMR1OrLater ? Runtime.getRuntime().availableProcessors() : 2, 1);
+    private static final int maxThreads = Math.max(AndroidUtil.isJellyBeanMR1OrLater ? Runtime.getRuntime().availableProcessors() : 2, 1);
     public static final ThreadFactory THREAD_FACTORY = new ThreadFactory() {
         @Override
         public Thread newThread(Runnable runnable) {
@@ -80,9 +80,9 @@ public class VLCApplication extends Application {
             return thread;
         }
     };
-    private final ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(Math.min(2, maxThreads), maxThreads, 30, TimeUnit.SECONDS,
+    private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(Math.min(2, maxThreads), maxThreads, 30, TimeUnit.SECONDS,
             new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY);
-    private Handler mHandler = new Handler(Looper.getMainLooper());
+    private static final Handler handler = new Handler(Looper.getMainLooper());
 
     private static int sDialogCounter = 0;
 
@@ -167,16 +167,16 @@ public class VLCApplication extends Application {
 
     public static void runBackground(Runnable runnable) {
         if (Looper.myLooper() != Looper.getMainLooper()) runnable.run();
-        else instance.mThreadPool.execute(runnable);
+        else threadPool.execute(runnable);
     }
 
     public static void runOnMainThread(Runnable runnable) {
         if (Looper.myLooper() == Looper.getMainLooper()) runnable.run();
-        else instance.mHandler.post(runnable);
+        else handler.post(runnable);
     }
 
     public static boolean removeTask(Runnable runnable) {
-        return instance.mThreadPool.remove(runnable);
+        return threadPool.remove(runnable);
     }
 
     public static void storeData(String key, Object data) {



More information about the Android mailing list