PhilipsHue / PhilipsHueSDK-Java-MultiPlatform-Android

The Software Development Kit for Philips Hue Java Mulfi-Platform and Android (beta)
273 stars 214 forks source link

Connect twice in one app #19

Open tomu1907 opened 9 years ago

tomu1907 commented 9 years ago

Hi,

I have some special requirements.. ;)

I have an app which is connecting to the bridge as usual -> means that I implemented the connection like in the example (http://www.developers.meethue.com/documentation/java-sdk-getting-started#connectingToABridge). My app is using a BroadcastReceiver, so it is waking if some events come up. Is this BroadcastReceiver I want to connect to the bridge and do some color changes. The problem is now that it is sometimes not possible to connect because the other part of the app is already connected to the bridge. I get no error message but it seems to be that the method phHueSDK.isAccessPointConnected(lastAccessPoint) is hanging and do nothing.

Any suggestions how to solve these multiple connect to one bridge?

Thanks! tomu

SteveyO commented 9 years ago

Hi tomu,

It's a bit tricky this one without seeing your code. Nothing immediately springs to mind. The PHHueSDK is a singleton, so what you are doing should work in theory, providing you have not disconnected from the SDK.

The isAccessPointConnected method loops through the connected bridges, comparing the IP Address in the Bridge Config with the IP Address in the passed lastAccessPoint object. I can't really see how this can hang. Are you sure you are not getting any Exceptions/Errors in LogCat?

When the BroadcastReceiver wakes up, can you add a check to see if PHHueSDK.getInstance().getSelectedBridge() is null or not This will at least test to see if your PHSDK singleton is still alive.

Steve