diff --git a/src/com/connectsdk/discovery/DiscoveryManager.java b/src/com/connectsdk/discovery/DiscoveryManager.java index 21b26d98..e3e00f50 100644 --- a/src/com/connectsdk/discovery/DiscoveryManager.java +++ b/src/com/connectsdk/discovery/DiscoveryManager.java @@ -145,7 +145,9 @@ public enum PairingLevel { @endcode */ public static synchronized void init(Context context) { - instance = new DiscoveryManager(context); + if (instance == null) { + instance = new DiscoveryManager(context); + } } public static synchronized void destroy() { @@ -163,7 +165,9 @@ public static synchronized void destroy() { @endcode */ public static synchronized void init(Context context, ConnectableDeviceStore connectableDeviceStore) { - instance = new DiscoveryManager(context, connectableDeviceStore); + if (instance == null) { + instance = new DiscoveryManager(context, connectableDeviceStore); + } } /** @@ -182,7 +186,7 @@ public static synchronized DiscoveryManager getInstance() { * Direct use of this constructor is not recommended. In most cases, * you should use DiscoveryManager.getInstance() instead. */ - public DiscoveryManager(Context context) { + private DiscoveryManager(Context context) { this(context, new DefaultConnectableDeviceStore(context)); } @@ -191,7 +195,7 @@ public DiscoveryManager(Context context) { * Direct use of this constructor is not recommended. In most cases, * you should use DiscoveryManager.getInstance() instead. */ - public DiscoveryManager(Context context, ConnectableDeviceStore connectableDeviceStore) { + private DiscoveryManager(Context context, ConnectableDeviceStore connectableDeviceStore) { this.context = context; this.connectableDeviceStore = connectableDeviceStore; diff --git a/test/src/com/connectsdk/discovery/DiscoveryManagerTest.java b/test/src/com/connectsdk/discovery/DiscoveryManagerTest.java index 01a4ef02..01ca7db2 100644 --- a/test/src/com/connectsdk/discovery/DiscoveryManagerTest.java +++ b/test/src/com/connectsdk/discovery/DiscoveryManagerTest.java @@ -29,7 +29,8 @@ public class DiscoveryManagerTest { @Before public void setUp() { - discovery = new DiscoveryManager(RuntimeEnvironment.application); + DiscoveryManager.init(RuntimeEnvironment.application); + discovery = DiscoveryManager.getInstance(); } @Test