0

I have been using the Android AltBeacon Library to Monitor and Range iBeacons in the nearby vicinity. One specific requirement of this application is allowing scanning for beacon detection even when the application is in the background and completely stop when the application is closed.

This requirement as I understand can be partially satisfied through BootstrapNotifier/RegionBootstrap but the scanning service restarts itself even when the application is closed which I don't want to happen.

My workaround was to implement all the scanning logic in a separate service that can be stopped and started as required. Having said that, the AltBeacon library at its core is itself a service so essentially I am running a service within a service which doesn't really make a lot of sense.

Are there any better ways to do that ? Any ideas would be appreciated.

Aneeb Khawar
  • 330
  • 1
  • 8

1 Answers1

1

If you don't want to have the library restart its scanning automatically, you can disable its StartupBroadcastReceiver by editing the ApplicationManifest.xml like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" ... >
  <application ... >
    <receiver android:name="org.altbeacon.beacon.startup.StartupBroadcastReceiver" 
              tools:node="remove" />
    ...

Keep in mind, however, that the operating system will stop your application from running in the background in low memory situations, even if the user doesn't explicitly close it. So you may find that if you disable this, your app won't keep scanning for beacons in the background as long as you think.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Thank you David. Rethinking this low memory scenario is rather compelling. Perhaps I should keep on running it in a custom service then. – Aneeb Khawar Sep 06 '16 at 19:50
  • A custom service won't stop the app from getting killed in a low memory scenario. That's why I commonly see Pandora or a podcast app stop playing when I am doing something memory intensive on my phone. This is the whole point of the Android Beacon Library scheduling itself to restart in the future in case this happens. – davidgyoung Sep 06 '16 at 20:34
  • Yes to account for that situation I have put in some addition logic with Alarm Manager to ensure that the service is running after a specific interval and then cancel the Alarm Manager altogether once done. It is kind of re-inventing the wheel. – Aneeb Khawar Sep 06 '16 at 21:31