1. Download our Official Android App: Forums for Android!

Support Service and Activity connection

Discussion in 'Android Help' started by gabyft45ol, Mar 3, 2016.

  1. gabyft45ol

    gabyft45ol Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Mar 3, 2016

    Mar 3, 2016
    1
    0
    5
    Male
    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:
    Code (Text):
    1.  if (device.getConnectionState() == AnDeviceBluetoothLE.STATE_CONNECTED) {...}
    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.
     

    Advertisement

Share This Page

Loading...