diff options
author | Petre Eftime <[email protected]> | 2016-02-19 18:29:54 +0200 |
---|---|---|
committer | Petre Eftime <[email protected]> | 2016-03-07 11:50:01 +0200 |
commit | 52fa7695084e3dbe9a63df4f4053424f5883d81a (patch) | |
tree | cb46a9a74b28223f04e6ad2814eca7bd1431cb38 /examples | |
parent | dbba04ae532868c7b43aa420b0db9c475a5aaec9 (diff) |
examples: java: Improve shutdown handling
Signed-off-by: Petre Eftime <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/java/HelloTinyB.java | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/examples/java/HelloTinyB.java b/examples/java/HelloTinyB.java index 2a2fbb26..2469f05b 100644 --- a/examples/java/HelloTinyB.java +++ b/examples/java/HelloTinyB.java @@ -93,18 +93,6 @@ public class HelloTinyB { System.exit(-1); } - final Thread mainThread = Thread.currentThread(); - Runtime.getRuntime().addShutdownHook(new Thread() { - public void run() { - running = false; - try { - mainThread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - }); - /* * To start looking of the device, we first must initialize the TinyB library. The way of interacting with the * library is through the BluetoothManager. There can be only one BluetoothManager at one time, and the @@ -141,6 +129,15 @@ public class HelloTinyB { System.exit(-1); } + final Thread mainThread = Thread.currentThread(); + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + running = false; + sensor.disconnect(); + } + }); + + BluetoothGattService tempService = getService(sensor, "f000aa00-0451-4000-b000-000000000000"); if (tempService == null) { |