onBeaconsDiscovered and Threads

Hey all,

I’m having some troubles using threads and ranging in my app.

beaconManager.setRangingListener(new BeaconManager.RangingListener() {
        public void onBeaconsDiscovered(Region region, List<Beacon> list) {         

Does the code in onBeaconsDiscovered run on a separate thread? If I want to use an AsyncTask in my code, is it better to open a new thread to each beacon discovered or to send the whole discovered list to the same AsyncTask? Known that the same beacons are discovered multiple times in a short period of time…

onBeaconsDiscovered is called on the main thread. (Or, to be more precise, on the message queue of the thread that instantiated the BeaconManager.) If you want to perform some heavy-duty tasks in it, AsyncTask is a good idea.

Correct, although you may try to influence that with setForegroundScanPeriod. For example, tell it to scan for 5 seconds instead of the default 1 second.