I asked various forms of this question before and got different opinions. Basically, I was advised to do some reading and experimenting. But to no avail. I still do not understand the alternative solutions that have been proposed. Again, I am developing an Android application that displays Bluetooth data .
I have a bluetooth activity which apparently creates a background stream that updates the screen with the data it receives via a bluetooth connection. When I run another / new action to build the data, I see that the bluetooth background stream continues to be written to Logcat. So, I know that the bluetooth background thread still works when I start my Plot activity .
My goal is to draw bluetooth data that is constantly provided by the bluetooth background stream. I succeeded in the following: since this bluetooth background thread is still running, I decided to use its update () method to call the static Plot.plotData () method to build the data. And it works , but I don’t understand why. It will work endlessly without problems - receiving and printing Bluetooth data .
But I was informed that this is probably not a very good solution because of the possible: thread safety, memory leak, blocking the main line of the user interface, etc. Although I have not encountered any of these problems, I am reluctant to finish my decision is good because of the feedback I received.
It has been suggested that I am trying to use Service, AsyncTask, etc. instead of calling the static method, my Plot.plotData (), from the bluetooth stream update method. But from the research that I did, I do not understand how to change my decision to a more suitable one.
If someone sees a more suitable solution, please speak and describe it. I do not want to move forward if there is a problem with my current solution .
If you want to see the source code, I would be happy to publish it.