Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have recently created an Android application that communicates to a hardware device over Bluetooth. In my application, I have many Activity classes that communicate through the connection, and the application also performs continuous data logging from the connection in the background, too. Therefore, hopefully I might be able to help here. (This is my first attempt at posting an answer on StackOverflow, so go easy on me.)</p> <p>In my application, I have first of all put all of the Bluetooth code into a separate dedicated class file (which I call BluetoothIF.java). The constructor in this class performs basic adapter initialization, and further methods are provided for tasks like making connections, etc. It contains the Runnable classes for establishing a connection and then transmitting / receiving over the established connection. (Essentially it is based upon the BluetoothChat example.)</p> <p>I don’t need to perform a massive amount of communication over the Bluetooth connection, and I also needed to have a Service in the background to continuously monitor and log data from the connection as previously mentioned. So, I instantiated my BluetoothIF within the Service. Any Activity classes that need to exchange data over the existing Bluetooth connection do so in my application by exchanging messages with the Service.</p> <p>Alternatively, if you have no need for using a Service, perhaps you should share the Bluetooth object instance across Activitys using the singleton model or by extending the Application class. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload