ANR issue with AltBeacon in Android

47 views Asked by At

I am currently working with the AltBeacon library for beacon detection. However, I am encountering ANR issues in my app. After some investigation, I found that the BeaconService's methods are executed on the main thread. I have a few questions regarding this issue:

Is it a technical limitation of the AltBeacon library that the BeaconService's methods need to run on the main thread?

Are there any recommended strategies or workarounds to avoid ANR issues while using the AltBeacon library?

Is there any way to offload or optimize the heavy processing that occurs during beacon detection to prevent UI thread contention?

I would greatly appreciate any insights or guidance on how to resolve this issue and improve the performance of my app. Thank you in advance for your help!

Additional Context:

I am using AltBeacon library version 2.19.4 in an android app. I tried to instantiate the library in different threads but could still see the comment confirming the scanning was happening on the main thread. There are not so many ANRs but they still exist and I would like to see how much better I could do following the right guidelines.

Note: Please let me know if you need any additional information or code samples to assist with troubleshooting this issue.

1

There are 1 answers

0
Some random IT boy On

The best way to offload work to a background thread if you're using Kotlin is to use coroutines. If you're still using Java you might just use Executors or any of the recommended libraries by the official documentation.

Now, without any code is very hard to help you troubleshoot your problem. Never worked myself with such library but I have implemented wrappers around Android's SDK.

Usually what you want to do is to run the scanning method on the background. OnClick handlers should use whatever way you chose to dispatch a background task and perform this operation