Introduction:
I want to create a multi-threaded Android application. My problem is the connection between threads. I read about the relationship between threads, and I came across things like the Looper / Handler design, which seemed pretty attractive and Atomic Variables like AtomicInteger. At the moment, I used AtomicInteger as a message, but since I am not very good at Java, I am not sure if this is bad in my case / if there is a better solution for my specific purpose. I was also a little suspicious of my method when I noticed that I really needed something like AtomicFloat, but it does not exist. I felt that I was losing sight of this concept. I also found that you can make AtomicFloat, but I'm just not sure if I am on the right track or there is a better technique.
Question:
Is it good / useful to use Atomic Variables and implement AtomicFloat for my specific purpose (described below), or is there a better way to handle the message?
Purpose / architecture of the application using AtomicVariables:
I have 4 Themes with the following purpose:
1.SensorThread: reads sensor data and stores the most recent values ββin AtomicVariables, for example
AtomicFloat gyro_z,AtomicFloat gyro_y, ...
2.CommunicationThread: communication with the PC, interprets the commands that enter the socket and sets the state of the application from the point of view of AtomicInteger: AtomicInteger state;
3.UIThread: displays the current sensor values ββfrom AtomicFloat gyro_z, AtomicFloat gyro_y,
4.ComputThread: uses sensor values AtomicFloat gyro_z,AtomicFloat gyro_y, ...and status AtomicInteger stateto perform calculations and send commands via USB.