title: Starting App in background when iBeacon detected
body: <p>I am experimenting the Android Beacon Library and I am able to make it working for monitoring and ranging with
  Apple compatible beacons adding a custom Parser (see <a href="https://stackoverflow.com/questions/25027983/is-this-the-correct-layout-to-detect-ibeacons-with-altbeacons-android-beacon-li">Is this the correct layout to detect iBeacons with AltBeacon&#39;s Android Beacon Library?</a>)</p>
  
  <p>Now I am trying to write an App which starts in background using the sample code shown here:</p>
  
  <p><a href="http://altbeacon.github.io/android-beacon-library/samples.html" rel="nofollow noreferrer">http://altbeacon.github.io/android-beacon-library/samples.html</a></p>
  
  <p>This is my code:</p>
  
  <pre><code>public class IBeaconBootstrap extends Application implements BootstrapNotifier {
  
  private RegionBootstrap regionBootstrap;
  
  @Override
  public void onCreate() {
  
      super.onCreate();
  
      Log.d("IBeaconBootstrap", "App started up");
  
      // wake up the app when any beacon is seen (you can specify specific id
      // filers in the parameters below)
  
      Region region = new Region("MyRegion", null, null, null);
      regionBootstrap = new RegionBootstrap(this, region);
  }
  
  @Override
  public void didDetermineStateForRegion(int state, Region region) {
      // Don't care
  
      // MonitorNotifier.INSIDE
  
      Log.d("Boostrap didDetermineStateForRegion", "Region " + region.toString());
  }
  
  @Override
  public void didEnterRegion(Region region) {
  
      Log.d("Boostrap didEnterRegion", "Got a didEnterRegion call");
  
      // This call to disable will make it so the activity below only gets
      // launched the first time a beacon is seen (until the next time the app
      // is launched)
      // if you want the Activity to launch every single time beacons come
      // into view, remove this call.
      regionBootstrap.disable();
  
      Intent intent = new Intent(this, MainActivity.class);
      // IMPORTANT: in the AndroidManifest.xml definition of this activity,
      // you must set android:launchMode="singleInstance" or you will get two
      // instances
      // created when a user launches the activity manually and it gets
      // launched from here.
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      this.startActivity(intent);
  }
  
  @Override
  public void didExitRegion(Region region) {
  
      Log.d("Boostrap didExitRegion", "Got a didExitRegion call");
  }
  }
  </code></pre>
  
  <p>Unfortunately, it doesn't work. These functions are never called:</p>
  
  <ul>
  <li>public void didDetermineStateForRegion(int arg0, Region arg1)</li>
  <li>public void didEnterRegion(Region arg0)</li>
  <li>public void didExitRegion(Region arg0)</li>
  </ul>
  
  <p>I expected that at least didDetermineStateForRegion were called creating the RegionBootstrap.</p>
  
  <p>Questions:</p>
  
  <p>0) What am I missing?</p>
  
  <p>1) Does this feature also work with Apple compatible iBeacons?</p>
  
  <p>2) Do I have to add a custom Parser? Where/How?</p>
  
  <p>Thank you in advance.</p>
  
  <p><strong>UPDATE 0</strong>:</p>
  
  <p>Following the davidgyoung directions I eventually got it working, changing the onCreate function as follows:</p>
  
  <pre><code>@Override
  public void onCreate() {
  
      Log.d("IBeaconBootstrap", "App started up");
  
      // wake up the app when any beacon is seen (you can specify specific id
      // filers in the parameters below)
  
      Region region = new Region("MyRegion", null, null, null);
      regionBootstrap = new RegionBootstrap(this, region);
  
      BeaconManager.getInstanceForApplication(this).getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
  
      super.onCreate();
  }
  </code></pre>
  
  <p>I have two more questions:</p>
  
  <p>0) The app checks every 3-5 minutes for the presence of iBeacons, is there any way to statically or dynamically change this interval?</p>
  
  <p>1) Apparently, the app goes foreground when detects an iBeacon if it is running but nothing happens if the app is not running. Is this the expected behavior or the app is supposed to be started if it is not running?</p>