diff --git a/src/main/java/org/altbeacon/beacon/BeaconIntentProcessor.java b/src/main/java/org/altbeacon/beacon/BeaconIntentProcessor.java index bb2e30ec2..1ac286b3f 100644 --- a/src/main/java/org/altbeacon/beacon/BeaconIntentProcessor.java +++ b/src/main/java/org/altbeacon/beacon/BeaconIntentProcessor.java @@ -27,6 +27,9 @@ import org.altbeacon.beacon.service.MonitoringData; import org.altbeacon.beacon.service.RangingData; +import android.os.Handler; +import android.os.Looper; + import android.annotation.TargetApi; import android.app.IntentService; import android.content.Intent; @@ -44,6 +47,19 @@ public BeaconIntentProcessor() { @Override protected void onHandleIntent(Intent intent) { + //Make sure we always deliver results on the main thread + if (Looper.getMainLooper().getThread() != Thread.currentThread()) { + Handler mainHandler = new Handler(Looper.getMainLooper()); + + Runnable myRunnable = new Runnable() { + @Override + public void run() { + onHandleIntent(intent); + } + }; + mainHandler.post(myRunnable); + return; + } LogManager.d(TAG, "got an intent to process"); MonitoringData monitoringData = null;