gabyft45ol
Lurker
Hello,
I have a device that measure the heart rate, and send the value to my application with bluetooth LE. I created a class AnDeviceBluetoothLE, that control the bluetooth. In my Activity I have an object device from this class, and functions like device.getConnexionState() or device.setMode(int m) are used in this Activity. When the device get a new value of heart rate, it display on Activity with Activity.setData(...).
Everything works, but when I close the application the bluetooth connection stop. So I want to create a Service with my object device, and establish a communication between my Service and my Activity:
-My Activity ask the Service the connection state, the Service give the value obtain with device.getConnexionState(), and the Activity can continue the others operations with the value.
for example, I currently have that in my Activity:
So if I put the device in a Service and use BroadcastManager to send demand and receive value, will my Activity wait to receive the value before doing the if?
-The Service must send the measurements, but only when the Application is opened.
How the Service can know if the Activity is opened or not?
Thanks.
I have a device that measure the heart rate, and send the value to my application with bluetooth LE. I created a class AnDeviceBluetoothLE, that control the bluetooth. In my Activity I have an object device from this class, and functions like device.getConnexionState() or device.setMode(int m) are used in this Activity. When the device get a new value of heart rate, it display on Activity with Activity.setData(...).
Everything works, but when I close the application the bluetooth connection stop. So I want to create a Service with my object device, and establish a communication between my Service and my Activity:
-My Activity ask the Service the connection state, the Service give the value obtain with device.getConnexionState(), and the Activity can continue the others operations with the value.
for example, I currently have that in my Activity:
Code:
if (device.getConnectionState() == AnDeviceBluetoothLE.STATE_CONNECTED) {...}
-The Service must send the measurements, but only when the Application is opened.
How the Service can know if the Activity is opened or not?
Thanks.