First, I should be clear by providing a little background: I’m using Eclipse to develop an Android application that plots Bluetooth data. It consists primarily of a Bluetooth Activity, a background thread created by the Bluetooth Activity, and a Plotting Activity.
The primary focus of my question: Once the Plotting Activity is known to be active, what approach can I use to send BluetoothData from the background thread to the Plotting Activity so I can plot it?
This is open source code that I am hacking. Using Logcat I know for a fact that the Bluetooth Activity created a background thread for continually producing BluetoothData even after the Bluetooth Activity is gone. And I have found the background method that logs the BluetoothData to Logcat. Now I want to leverage this method to send BluetoothData to the active Plotting Activity so I can plot it.
I can tell you what appears to work. Interested? Define a static method, plotData(BluetoothData) in the Plotting Activity and call if from the background thread. Clips along in real-time just fine. The plots are nice. But I’ve been told I shouldn’t have to use static methods as though there is some problem with that. So what else should I use?
Any suggestions?
You shouldn’t use a
background thread. Instead you should use aServicethat collects the data. In this case every activity you create can bind to that service and be informed if new data was received. With a handler, the service can easily send the data to the activity that is binded.A little question: Can you please explain why there should be a problem with static methods and more precisely: which kind of problems?