Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any change in the ScannerStateLiveData will restart the scan #31

Open
eliotstock opened this issue Oct 25, 2019 · 1 comment
Open

Any change in the ScannerStateLiveData will restart the scan #31

eliotstock opened this issue Oct 25, 2019 · 1 comment
Labels

Comments

@eliotstock
Copy link

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.

@philips77
Copy link
Member

Thank for reporting this. We have no time to fix it soon, but will eventually handle it.

@philips77 philips77 added the bug label Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants