question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem Detecting Existing Beacons After App Restart

See original GitHub issue

Expected 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:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
davidgyoungcommented, Jun 22, 2018

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:

06-22 10:37:44.490 18003-18142/org.altbeacon.beaconreference D/ScanHelper: Beacon packet detected for: id1: 9304fd9d-4276-4442-980f-ff8739a9efd4 id2: 10004 id3: 54480 with rssi -52

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 with beaconManager.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.

0reactions
davidgyoungcommented, Jan 9, 2019

closing due to inactivity

Read more comments on GitHub >

github_iconTop Results From Across the Web

AltBeacon library inconsistent when detecting a beacon after ...
Often, the app will stop detecting the beacon after first pause/resume. It seems to be random. Often it will survive multiple pauses. I...
Read more >
I can't detect beacons in the Estimote app
In order to figure out where the problem really is, please try the following steps and check if beacons appear again after each...
Read more >
iBeacon detection in background so… - Apple Developer
When a user first shows up the beacon aspect of the app usually works no problem. However when they set off on their...
Read more >
Troubleshooting iBeacon Background Triggering - BeaconZone
Go to Settings… General and select 'Reset'. Select 'Reset All Settings'. The phone will reboot. You will need to set up things like...
Read more >
Android Beacon Library
When an app stops in cases 2-5, the application's background services are terminated by Android OS, meaning that beacon detections are no longer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found