Problem Detecting Existing Beacons After App Restart
See original GitHub issueExpected behavior
After the reference app is restarted it should report on nearby beacons, either via didEnterRegion
or didDetermineStateForRegion
.
Actual behavior
After restart no initial didDetermineStateForRegion
event is delivered. After a long pause on the order of minutes the reference app delivers pairs of “I no longer see a beacon”/“I see a beacon again” repeatedly, accompanied by the “I have just switched…” message.
However, the library does seem to know it’s inside a region, since you receive this log message:
06-21 17:16:58.495 2740-2740/org.altbeacon.beaconreference I/ScanJob: We are inside a beacon region. We will not scan between cycles.
One thing I did notice from time to time is that onCreate
is called again in the app around the same time it’s restarted. So you restart and you can see the UI redraw quickly before the second onCreate
event causes the UI to restart. But this doesn’t seem consistent.
Steps to reproduce this behavior
I’m using a BlueCharm beacon set to iBeacon mode and set to broadcast at 2Hz. I saw another post about setting it to broadcast at at least 10Hz (which seems quite high), so I tried that as well, but it made no difference. If you have suggestions about iBeacon hardware known to work better I’m all ears 😄.
Mobile device model and OS version
Google Pixel with Android 8.1.0.
Android Beacon Library version
2.14.
Thanks for all the hard work on this library!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
The log file covers about 90 seconds, and I see a beacon is detected by the library within 4 seconds of the start of the log:
But this won’t necessarily give you a callback to
didEnterRegion
if you were already in the region when the beacon was detected. And because the library persists region state across app restarts, this applies even when restarting your app (at least if the app had been last running within a reasonable amount of time ~15 min – this is done to prevent duplicate entry events across app restarts caused by the operating system.) You might wish to disable this behavior withbeaconManager.setRegionStatePersistenceEnabled(false)
which will always give you a callback on first detection after app restart.I believe the
didDetermineStateForRegion()
callback WILL get called in all cases on app restart. But because neither the library nor the reference app logs anything when this callback is made, I can’t tell for sure from the logs if this happens. You might try adding a log line to the reference app for this and see if you see it upon restart.closing due to inactivity