From 53ea3bb3313d1eb1b1a4501ed99f0b41b2e7785a Mon Sep 17 00:00:00 2001 From: "David G. Young" Date: Thu, 2 Apr 2015 17:50:55 -0400 Subject: [PATCH] Don't crash app if we fall behind on scans. Log a warning. --- .../org/altbeacon/beacon/service/BeaconService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/altbeacon/beacon/service/BeaconService.java b/src/main/java/org/altbeacon/beacon/service/BeaconService.java index a97fc1f36..ab9ea1cfb 100644 --- a/src/main/java/org/altbeacon/beacon/service/BeaconService.java +++ b/src/main/java/org/altbeacon/beacon/service/BeaconService.java @@ -57,6 +57,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.RejectedExecutionException; /** * @author dyoung @@ -297,8 +298,13 @@ public void setScanPeriods(long scanPeriod, long betweenScanPeriod, boolean back @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { - new ScanProcessor().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, - new ScanData(device, rssi, scanRecord)); + try { + new ScanProcessor().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, + new ScanData(device, rssi, scanRecord)); + } + catch (RejectedExecutionException e) { + Log.w(TAG, "Ignoring scan result because we cannot keep up.", e); + } } @Override