I want to experiment with iBeacon on Android. It looks like that AltBeacon is the best tool to use. I read that if I subclass the application of my app to this, I can make my app works even though the app is killed the afterward.
What if I want to my app to monitor only if the user logged in? The Application will run each the app is launched, won't it? How to run the BootstrapNotifier in Application after login and not run it if the user isn't logged in?
@Override
protected void onPostExecute(final Boolean success) {
if (success) {
//algorithm to make altbeacon run in the background, even after the app killed
} else {
//if failed
}
}
So, here is the proposed solution:
public class BeaconReferenceApplication extends Application implements BootstrapNotifier {
// OTHER CODE
public void onCreate() {
super.onCreate();
if (loggedin) {
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
Region region = new Region("backgroundRegion", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
BeaconManager.getBeaconSimulator()).createTimedSimulatedBeacons();
}
}
// OTHER CODE
}
public class LoginACtivity {
// OTHER CODE
public void onClick {
if (username == TRUE && password == TRUE) {
// SINCE THE USER LOGGED IN, HOW DO I MAKE MY APP TO START ALWAYS SCAN EVEN AFTER REBOOTING AS LONG THE USER ISN'T LOGGING OUT?
}
}
// OTHER CODE
}
public class MainActivity {
// OTHER CODE
private void logout {
// SINCE THE USER CLICK LOG OUT BUTTON, HOW DO I MAKE MY APP TO STOP SCANNING EVEN AFTER REBOOTING UNTIL THE USER LOGGING IN AGAIN?
}
// OTHER CODE
}
Is that code will guarantee my app to always scan for beacon only if the user is loggedin, even after rebooting and the app isn't running?