File tree Expand file tree Collapse file tree
src/main/java/org/altbeacon/beacon/service/scanner Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -157,8 +157,6 @@ public void stop() {
157157 mScanningEnabled = false ;
158158 if (mScanCyclerStarted ) {
159159 scanLeDevice (false );
160- LogManager .d (TAG , "forcing scanning to stop even for devices capable of multiple detections per cycle" );
161- stopScan ();
162160 } else {
163161 LogManager .d (TAG , "scanning already stopped" );
164162 }
@@ -173,7 +171,20 @@ public void setDistinctPacketsDetectedPerScan(boolean detected) {
173171 }
174172
175173 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+ });
177188 }
178189
179190 protected abstract void stopScan ();
Original file line number Diff line number Diff line change @@ -223,6 +223,7 @@ private void postStopLeScan() {
223223 @ Override
224224 public void run () {
225225 try {
226+ LogManager .d (TAG , "Stopping LE scan on scan handler" );
226227 scanner .stopScan (scanCallback );
227228 } catch (IllegalStateException e ) {
228229 LogManager .w (TAG , "Cannot stop scan. Bluetooth may be turned off." );
You can’t perform that action at this time.
0 commit comments