Merge branch 'fix/handler-postdelayed-cancel': cancel pending BLE scans on pause

This commit is contained in:
eddy 2026-07-26 16:53:22 +02:00
commit d2faaf8fbc

View file

@ -49,6 +49,7 @@ class MainActivity : AppCompatActivity() {
private var isScanning = false
private var scanTimedOut = false
private val handler = Handler(Looper.getMainLooper())
private val scanRunnable = Runnable { startScan() }
private var seq = 1
private var hmacKey: ByteArray? = null
@ -89,7 +90,7 @@ class MainActivity : AppCompatActivity() {
bluetoothGatt = null
relayCharacteristic = null
seq = 1
handler.postDelayed({ startScan() }, 2000)
handler.postDelayed(scanRunnable, 2000)
}
}
@ -165,7 +166,7 @@ class MainActivity : AppCompatActivity() {
relayCharacteristic = null
seq = 1
loadHmacKey()
handler.postDelayed({ startScan() }, 500)
handler.postDelayed(scanRunnable, 500)
}
}
@ -175,12 +176,13 @@ class MainActivity : AppCompatActivity() {
if (hmacKey == null) {
statusText.text = "Geen HMAC sleutel - open Instellingen"
} else if (!isScanning && bluetoothGatt == null) {
handler.postDelayed({ startScan() }, 300)
handler.postDelayed(scanRunnable, 300)
}
}
override fun onPause() {
super.onPause()
handler.removeCallbacks(scanRunnable)
stopScan()
}