[Android] Simplify Medialibrary Singleton
Geoffrey Métais
git at videolan.org
Thu Oct 5 15:05:17 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 5 13:18:29 2017 +0200| [8ca19844e7176d429eeb5de953f4b18923a85b35] | committer: Geoffrey Métais
Simplify Medialibrary Singleton
> https://code.videolan.org/videolan/vlc-android/commit/8ca19844e7176d429eeb5de953f4b18923a85b35
---
.../src/org/videolan/medialibrary/Medialibrary.java | 13 ++++++-------
vlc-android/src/org/videolan/vlc/VLCApplication.java | 6 +-----
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 7993f3ac1..1ca67ebd2 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -45,7 +45,6 @@ public class Medialibrary {
public static final int FLAG_MEDIA_ADDED_AUDIO_EMPTY = 1 << 4;
public static final int FLAG_MEDIA_ADDED_VIDEO = 1 << 5;
- private static final String extDirPath = Environment.getExternalStorageDirectory().getAbsolutePath();
public static final String ACTION_IDLE = "action_idle";
public static final String STATE_IDLE = "state_idle";
@@ -66,8 +65,6 @@ public class Medialibrary {
private AlbumsModifiedCb mAlbumsModifiedCb = null;
private final List<DevicesDiscoveryCb> devicesDiscoveryCbList = new ArrayList<>();
private final List<EntryPointsEventsCb> entryPointsEventsCbList = new ArrayList<>();
-
- private static Medialibrary sInstance;
private static Context sContext;
static {
@@ -76,6 +73,10 @@ public class Medialibrary {
System.loadLibrary("mla");
}
+ private static class MedialibraryHolder {
+ public static final Medialibrary instance = new Medialibrary();
+ }
+
public static Context getContext() {
return sContext;
}
@@ -142,10 +143,8 @@ public class Medialibrary {
super.finalize();
}
- public static synchronized Medialibrary getInstance() {
- if (sInstance == null)
- sInstance = new Medialibrary();
- return sInstance;
+ public static Medialibrary getInstance() {
+ return MedialibraryHolder.instance;
}
@WorkerThread
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 3b5c3bb5c..5e3a6ead3 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -60,7 +60,6 @@ public class VLCApplication extends Application {
public final static String ACTION_MEDIALIBRARY_READY = "VLC/VLCApplication";
private static volatile VLCApplication instance;
- private static volatile Medialibrary sMedialibraryInstance;
public final static String SLEEP_INTENT = Strings.buildPkgString("SleepIntent");
@@ -243,10 +242,7 @@ public class VLCApplication extends Application {
}
public static Medialibrary getMLInstance() {
- if (sMedialibraryInstance == null) {
- sMedialibraryInstance = Medialibrary.getInstance();
- }
- return sMedialibraryInstance;
+ return Medialibrary.getInstance();
}
public static void setLocale(){
More information about the Android
mailing list