kai-morich / SimpleBluetoothLeTerminal

Android terminal app for Bluetooth LE devices using custom serial profiles
MIT License
288 stars 111 forks source link

Is removeCallbacks(this::stopScan) correct? #33

Closed albtrentadue closed 2 years ago

albtrentadue commented 2 years ago

This is a minor remark, since the app still works well. However, I would like to check my understanding

The following line (264) in DeviceFragment.java seems not correct to me:

leScanStopHandler.removeCallbacks(this::stopScan);

This because, as far as I know, when you pass a method to a Handler in postDelayed(), it gets encapsulated in a Runnable object and then scheduled. Calling removeCallbacks without referencing the original Runnable object should not do what was intended for. Am I correct?

Thanks!

kai-morich commented 2 years ago

you're right. its exactly the issue I prevented here: https://github.com/kai-morich/SimpleUsbTerminal/blob/8432483e29da6d36a7e7caf752319846a67e9f12/app/src/main/java/de/kai_morich/simple_usb_terminal/TerminalFragment.java#L401