Program Dangling? (Thread still active) #21
Description
Hello,
I think this is going back to a previous issue listed here - #13.
I have built a java program where I want to change a few configurations on the lights. To keep it as relevant as possible, here is the following code I altered from the original Java Desktop App:
private PHSDKListener listener = new PHSDKListener() {
@Override
public void onAccessPointsFound(List<PHAccessPoint> accessPointsList) {
System.out.println("INFO: Found Access Points! Using the first one");
// Get the first Access Point listed
phHueSDK.connect(accessPointsList.get(0));
}
@Override
public void onAuthenticationRequired(PHAccessPoint accessPoint) {
// Start the Pushlink Authentication.
System.out.println("INFO: Press the link button on the bridge to authenticate");
phHueSDK.startPushlinkAuthentication(accessPoint);
}
@Override
public void onBridgeConnected(PHBridge bridge, String username) {
phHueSDK.stopPushlinkAuthentication();
System.out.println("Connected to the bridge!");
phHueSDK.setSelectedBridge(bridge);
phHueSDK.enableHeartbeat(bridge, PHHueSDK.HB_INTERVAL);
String lastIpAddress = bridge.getResourceCache().getBridgeConfiguration().getIpAddress();
HueProperties.storeUsername(username);
HueProperties.storeLastIPAddress(lastIpAddress);
HueProperties.saveProperties();
randomLights();
phHueSDK.disableAllHeartbeat();
phHueSDK.destroySDK();
}
...
As you can see in the "onBridgeConnected()", I want to run the "randomLights()" method as soon as I am connected to the bridge and then immediately close the SDK and exit the program. I found that if the properties are saved in a separate file, this works completely fine. However, if I run this for the very first time where I have to to push the link button for authentication, the program dangles and does not exit. Any suggestions on how to fix this issue? I know I can use System.exit() but feel that this is the unclean version of how to fix the issue.
Thank you,
Zack