BluetoothLE: It is advisable to index DeviceList before StopScanning?

It is advisable to index DeviceList before StopScanning?

ListView.Elements, for example, is populated with DeviceList, in the same order, when DeviceFound occurs. If the user selects an item from ListView in order to connect the device at that index, but suddenly, new devices is found by the scanner and DeviceList changes, then the saved index may no longer be valid, right?

If that possibility exists, what is advisable to do?
Maybe reset a timer when every DeviceFound occurs, and if timer expires (no more device found in a few seconds), then StopScanninng automatically and allow indexing of the DeviceList.

Any comments,
Osmany

I am not really sure what you mean by indexing the device list, but I am pretty sure that it is advisable to stop scanning first.

1 Like

Thanks @Ghica for your answer,

Now, I am stopping the scan and then allowing the user to connect to the device at the ListView.SelectionIndex.

Best regards,
Osmany

Note that this also depends on the extension version you are using. Newer versions maintain a stable ordering of the devices in the list. Older versions would produce a "random" ordering based on the hashes of the MAC addresses of all of the discovered devices, so as new devices were discovered during a scan, new devices would be inserted at random points in the exist list. For safety it is as Ghica says to stop scanning first to ensure the list won't change regardless of the BLE extension's behavior.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.