You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's how you hook your ScannerViewModel up in your activity:
// Create view model containing utility methods for scanning
mScannerViewModel = ViewModelProviders.of(this).get(ScannerViewModel.class);
mScannerViewModel.getScannerState().observe(this, this::startScan);
Are you sure this is a good idea?
This means that any change in the ScannerStateLiveData, including a new scan result showing up, will cause a postValue() which will cause another call to startScan(). That then calls ScannerViewModel.startScan(), which bails out if it's already scanning. So far so good.
The problem comes when I want to stop scanning once I've tapped on a device. ScannerViewModel.stopScan() will call scannerStateLiveData.scanningStopped(), but that will immediately call postValue() which will cause the activity's startScan() method to be called again. Given I'm in the middle of trying to connect to a device at this point, I think this is bad for the Android BLE stack.
The text was updated successfully, but these errors were encountered:
Here's how you hook your
ScannerViewModel
up in your activity:Are you sure this is a good idea?
This means that any change in the
ScannerStateLiveData
, including a new scan result showing up, will cause apostValue()
which will cause another call tostartScan()
. That then callsScannerViewModel.startScan()
, which bails out if it's already scanning. So far so good.The problem comes when I want to stop scanning once I've tapped on a device.
ScannerViewModel.stopScan()
will callscannerStateLiveData.scanningStopped()
, but that will immediately callpostValue()
which will cause the activity'sstartScan()
method to be called again. Given I'm in the middle of trying to connect to a device at this point, I think this is bad for the Android BLE stack.The text was updated successfully, but these errors were encountered: