Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This moves the
BeaconService
call to promote itself to a foreground service to the first line inonCreate
. This is done in an attempt to avoid crashes initiated by Android caused by the failure to promote a service to a foreground service within 5 seconds. Such an exception looks like this:Because the service is started on the main thread, it is possible that if that thread is very busy or blocked (potentially by other apps!) then it may take a long time to even call this onCreate method. In some cases where the main thread is busy or blocked, it may not be possible to do this in 5 seconds. Forum posts are full of claims from crash logs that this happens sometimes.
This is no guaranteed fix. But moving this to the top of the method gives the best thing that this library can do to prevent this crash. The app developer needs to take care not to initialize this library to start scanning in a case where the main thread could be blocked or overly busy. In other words, don't initialize beacon scanning then immediately do a large amount of work on the main thread.
This is in the 2.19-beta version of the library