How to change Monitored Region with altbeacon library?
<p>Making an application, where it scans in background only for one specific iBeacon. But in Activity I can change it to what ever I want it to scan for. 
I'm using the altbeacon library and the sample code. Already made it scan for a specific iBeacon, but I can't get it to change the Region.</p>

<p>One way I could think of, is, to get a Global static String. That way I can edit and beaconManager after bind will have the new Region. 
(<a href="https://stackoverflow.com/questions/21810240/how-to-create-a-global-variable-in-android">How to create a global variable in android?</a>)
But I can only get.. not set.. , after I destroy Activity its empty.</p>

<p>Other way is to do it straight in the Activity, after click Save it just changes it. But that didn't seem to work.</p>

<p>iBeaconReader.java</p>

<pre><code>public class iBeaconReader extends Application implements BootstrapNotifier {

private static final String TAG = "BeaconReferenceApp";
private BeaconManager beaconManager;
private RegionBootstrap regionBootstrap;
private BackgroundPowerSaver backgroundPowerSaver;

public void onCreate() {
    super.onCreate();
    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.setBackgroundMode(true);
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.setBackgroundBetweenScanPeriod(1000l);
    beaconManager.setBackgroundScanPeriod(1000L);
    beaconManager.bind(this);

    Identifier identifier = Identifier.parse("9B749762-760E-4AD8-A221-000000000000");   // I dont want to find this. 
    Region region = new Region("null", null, null, null);                               // But I have to set it up

    regionBootstrap = new RegionBootstrap(this, region);

    backgroundPowerSaver = new BackgroundPowerSaver(this);

}

@Override
public void didEnterRegion(Region region) {
    if(!region.getUniqueId().equals("null")) {
        Log.d(TAG, "In Range- " + region);
    }
}

@Override
public void didExitRegion(Region region) {
    if(!region.getUniqueId().equals("null")) {
        Log.d(TAG, "Out of Range- " + region);
    }
}

@Override
public void didDetermineStateForRegion(int i, Region region) {

}
}
</code></pre>

<p>MainActivity.java</p>

<pre><code>public class MainActivity extends Activity implements BeaconConsumer {
...

@Override
protected void onCreate(Bundle savedInstanceState) {
    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.bind(this);

...

@Override
protected void onDestroy() {
    super.onDestroy();
    beaconManager.unbind(this);
}

...
@Override
public void onBeaconServiceConnect() {
    try {
        beaconManager.stopMonitoringBeaconsInRegion(new Region("backgroundRegion", null, null, null));
        Identifier identifier = Identifier.parse("9B749762-760E-4AD8-A221-91E0F210134C"); //mini beacon
        beaconManager.startMonitoringBeaconsInRegion(new Region("backgroundRegion", identifier, null, null));
    } catch (RemoteException e) {
        Log.e("BeaconReferenceApp", e.getMessage(), e);
    }
}
</code></pre>

<p>I got it working. When the <code>onBeaconServiceConnect()</code> function gets called I have to do <code>beaconManager.stopMonitoringBeaconsInRegion(new Region("backgroundRegion", null, null, null))</code>.
When I didn't stopMonitoring, it didn't change the monitoring region.</p>