diff --git a/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java b/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java index 9e30960f6..e2f6a3e2d 100644 --- a/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java +++ b/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java @@ -54,6 +54,7 @@ public class ScanJob extends JobService { @Nullable private ScanHelper mScanHelper; private boolean mInitialized = false; + private boolean mStopCalled = false; @Override public boolean onStartJob(final JobParameters jobParameters) { @@ -87,6 +88,12 @@ public void run() { } LogManager.d(TAG, "Done processing queued scan resuilts"); + if (mStopCalled) { + LogManager.d(TAG, "Quitting scan job before we even start. Somebody told us to stop."); + ScanJob.this.jobFinished(jobParameters , false); + return; + } + boolean startedScan; if (mInitialized) { LogManager.d(TAG, "Scanning already started. Resetting for current parameters"); @@ -176,6 +183,7 @@ private void startPassiveScanIfNeeded() { @Override public boolean onStopJob(JobParameters params) { + mStopCalled = true; if (params.getJobId() == getPeriodicScanJobId(this)) { LogManager.i(TAG, "onStopJob called for periodic scan " + this); }