Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain a single static instance of DiscoveryManager. #91

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/com/connectsdk/discovery/DiscoveryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}

/**
Expand All @@ -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));
}

Expand All @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion test/src/com/connectsdk/discovery/DiscoveryManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class DiscoveryManagerTest {

@Before
public void setUp() {
discovery = new DiscoveryManager(RuntimeEnvironment.application);
DiscoveryManager.init(RuntimeEnvironment.application);
discovery = DiscoveryManager.getInstance();
}

@Test
Expand Down