File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
src/main/java/org/altbeacon/beacon/service/scanner Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -157,8 +157,6 @@ public void stop() {
157
157
mScanningEnabled = false ;
158
158
if (mScanCyclerStarted ) {
159
159
scanLeDevice (false );
160
- LogManager .d (TAG , "forcing scanning to stop even for devices capable of multiple detections per cycle" );
161
- stopScan ();
162
160
} else {
163
161
LogManager .d (TAG , "scanning already stopped" );
164
162
}
@@ -173,7 +171,20 @@ public void setDistinctPacketsDetectedPerScan(boolean detected) {
173
171
}
174
172
175
173
public void destroy () {
176
- mScanThread .quit ();
174
+ LogManager .d (TAG , "Destroying" );
175
+ // We cannot quit the thread used by the handler until queued Runnables have been processed,
176
+ // because the handler is what stops scanning, and we do not want scanning left on.
177
+ // So we stop the thread using the handler, so we make sure it happens after all other
178
+ // waiting Runnables are finished.
179
+ mHandler .post (new Runnable () {
180
+ @ Override
181
+ public void run () {
182
+ LogManager .d (TAG , "Quitting scan thread" );
183
+ // Remove any postDelayed Runnables queued for the next scan cycle
184
+ mHandler .removeCallbacksAndMessages (null );
185
+ mScanThread .quit ();
186
+ }
187
+ });
177
188
}
178
189
179
190
protected abstract void stopScan ();
Original file line number Diff line number Diff line change @@ -223,6 +223,7 @@ private void postStopLeScan() {
223
223
@ Override
224
224
public void run () {
225
225
try {
226
+ LogManager .d (TAG , "Stopping LE scan on scan handler" );
226
227
scanner .stopScan (scanCallback );
227
228
} catch (IllegalStateException e ) {
228
229
LogManager .w (TAG , "Cannot stop scan. Bluetooth may be turned off." );
You can’t perform that action at this time.
0 commit comments