I appreciate an answer, considering that now is 2017 and newer Android versions like 7 (and 8 coming) have appeared since old questions asking something similar.
I want to monitor continuously (as long as the user is logged in my app) beacons in background, even if the app is killed by user or by system (when low memory) and for a long time (i.e. when the user needs some kind of help, the apps should be less probable to fail).
So the question here is which is the recommended method to do this:
Using regionBootstrap
as recommended here: http://altbeacon.github.io/android-beacon-library/samples.html and http://altbeacon.github.io/android-beacon-library/resume-after-terminate.html (Starting an App in the Background). I tried this but sometimes I got the monitoring working, sometimes not.
Using a background service which returns START_STICKY
. I tried this but it does not seems reliable and it seems that this prevents other apps to monitor beacons at the same time.
Using a background service that starts as startForeground
. I have not tried this.
Using the RegionBootstrap
class as described in the Starting App in the Background section of the sample code here is the recommended way of detecting in the background even after the app is killed.
Changes will likely be required to accomplish this for Android "O" due to Google's plans to restrict long running background services. These will be addressed in a future library version to be released before "O".