1. Are you ready for the Galaxy S20? Here is everything we know so far!

Service and Activity connection

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

  1. gabyft45ol

    gabyft45ol Lurker
    Thread Starter

    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.
     


Loading...
Similar Threads - Service Activity connection
  1. Alex Marasco
    Replies:
    0
    Views:
    150
  2. Loribelle1
    Replies:
    5
    Views:
    573
  3. mdsousa
    Replies:
    1
    Views:
    954
  4. rajdeeprockysarker
    Replies:
    0
    Views:
    249
  5. Jennifer catron
    Replies:
    2
    Views:
    451
  6. Gloria J Houston
    Replies:
    1
    Views:
    170
  7. timroosendaal
    Replies:
    1
    Views:
    843
  8. Kymberly70
    Replies:
    3
    Views:
    733
  9. Nightpoison
    Replies:
    0
    Views:
    474
  10. kilowog3000
    Replies:
    0
    Views:
    427

Share This Page

Loading...