I found out that, whenever the USB cable is disconnected and reconnected and UsbSerialDevice.createUsbSerialDevice is called again, the threads created by the previous call remain running and new ones are created. It seems that, on each call, the number of created threads increase, such that they pile up quite quickly after a few calls.
After some research (maybe related), I thought that calling UsbSerialDevice.close would be enough, but it wasn't.
Digging deeper, I downloaded the source code and used it in my project. Since I'm using a CH34x device, I edited CH34xSerialDevice and added the following method:
Hi everyone.
I found out that, whenever the USB cable is disconnected and reconnected and
UsbSerialDevice.createUsbSerialDevice
is called again, the threads created by the previous call remain running and new ones are created. It seems that, on each call, the number of created threads increase, such that they pile up quite quickly after a few calls.After some research (maybe related), I thought that calling
UsbSerialDevice.close
would be enough, but it wasn't.Digging deeper, I downloaded the source code and used it in my project. Since I'm using a CH34x device, I edited
CH34xSerialDevice
and added the following method:That fixed it without having to call
UsbSerialDevice.close
. Only one thread remained running at once.I don't have other devices to test if the issue exists with the other classes or, if it does, if this patch fixes it, so please take a look into it.
I tested with an Android 7.1.1.
Thanks in advance.