mik3y / usb-serial-for-android

Android USB host serial driver library for CDC, FTDI, Arduino and other devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onNewData is stopping current run

recser opened this issue · comments

Hello,
a question regarding any recommendations for implementing the onNewData functionality. Currently due to some processing inside onNewData method (splitting, deduping and so on) the execution of the method takes some small amount the time during which other new events of new data may come which interrupts current run and starts evaluating new data.
Is there a proven method to handle this kind of scenarios ?
I am currently implementing a queue based approach where onNewData would push new data into the queue, and another thread would read from that queue and process separately the data.
Was wondering if this is the right approach or if there are any other ways of achieving a completion of processing before new data comes in?

if your data should be shown on the UI you could process it asynchronously by the UI mainLooper, e.g. as done here and here. If appended to a TextView the UI processing gets slow when already a lot of text is shown, so the second linked variant also takes care of merging received data.

thank you for taking your time to answer, appreciated!