Rich Text Template 3

Project scene:

Example: Project scenario: Example: Communicate with mobile phone APP via Bluetooth chip (HC-05), and transmit a batch of sensor data every 5s (not very large)

Problem Description:

Example: During data transmission, data may be lost from time to time, and part of the data may be lost occasionally
. The receiving data code in APP:
@Override
public void run() { bytes = mmInStream.read(buffer); mHandler.obtainMessage(READ_DATA, bytes,- 1, buffer).sendToTarget(); }


Cause Analysis:

Example: There are two ways for Handler to send messages, namely Handler.obtainMessage() and Handler.sendMessage(). When the amount of data is too large in the obtainMessage method, the size of MessageQuene is also limited, so when the message is not processed in time, it will cause The data transmitted first is overwritten, resulting in data loss.

solution:

Example: Create a new Message object, and save the read data into Message, then mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget(); replace it with mHandler.sendMessage().

Guess you like

Origin blog.csdn.net/cpongo1/article/details/107985736