title: How to detect beacons using Android Beacon Library in foreground and background?
body: <p>I am trying to detect beacons while my app is running and put them in a list and also detect when not running and display a notification.  I can't seem to get both working at the same time on android.</p>
  
  <p>I have my main activity...</p>
  
  <pre><code>[Activity(LaunchMode = LaunchMode.SingleInstance, Label = "MyApp", Icon = "@mipmap/icon", MainLauncher = true, Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
  public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IMonitorNotifier, IRangeNotifier, IBeaconConsumer, IBootstrapNotifier
  
  protected override void OnCreate(Bundle savedInstanceState)
  {
      set beacon parsers
      beaconmanager.bind(this)
      ...
  
  public void OnBeaconServiceConnect()
  {
      BeaconManager.AndroidBeaconManager.RemoveAllMonitorNotifiers();
      BeaconManager.AndroidBeaconManager.RemoveAllRangeNotifiers();
  
      BeaconManager.AndroidBeaconManager.AddMonitorNotifier(this);
      BeaconManager.AndroidBeaconManager.AddRangeNotifier(this);
  
      StartMonitoringBeacons...
      StartRangingBeacons...
  }
  </code></pre>
  
  <p>Then I have a separate class...</p>
  
  <pre><code>[Activity(LaunchMode=LaunchMode.SingleInstance, Label="MyApp", MainLauncher = true)]
  public class LaunchApplication : Application, IBootstrapNotifier, IRangeNotifier, IBeaconConsumer
  {
      private RegionBootstrap _bootstrap = null;
  
      public override void OnCreate()
      {
          base.OnCreate();
  
          var proximities = BeaconManager.Instance.GetServerProximitiesAsync().GetAwaiter().GetResult();
          var regions = proximities.Select(x =&gt; new Region(x.UUID, null, null, null)).ToList();
  
          BeaconManager.GetParsers().ForEach(x =&gt; BeaconManager.AndroidBeaconManager.BeaconParsers.Add(x));
  
          _bootstrap = new RegionBootstrap(this, regions);
      }
      public void DidEnterRegion(Region region)
      {
          add parsers
          beaconmanager.bind(this);
      }
      public void OnBeaconServiceConnect()
      {
          BeaconManager.AndroidBeaconManager.AddMonitorNotifier(this);
          BeaconManager.AndroidBeaconManager.AddRangeNotifier(this);
  
          start monitoring...
          start ranging...
  </code></pre>
  
  <p>I don't add anything to my manifest because I believe it does automatically with the Activity attribute.</p>
  
  <p>My question is am I supposed to have a MainActivity and a separate class that derives from Application (that creates a region bootstrap)?</p>
  
  <p>do I bind to different instances (bind(this))?</p>
  
  <p>When I debug the LaunchApplication OnCreate never gets called so how does it ever create a region bootstrap?</p>
  
  <p>how am I supposed to set this up to just detect while running in foreground and background?</p>
  
  <p>Thanks.</p>