I am working with some Estimote beacons (basically bluetooth proximity beacons) and I am creating an android app that switches screens once it picks up a certain beacon.
public class MainActivity extends AppCompatActivity implements hold_undo_fragment.toggleButtonListener {
public void runBeaconDistances(){
final Intent i = new Intent(this, corsi.class);
final Intent j = new Intent(this, search_key.class);
final Intent k = new Intent(this, corsi2.class);
beaconDistances = new BeaconDistances(this, beaconIDs);
beaconDistances.setListener(new BeaconDistances.Listener() {
@Override
public void onBeaconDistancesChanged(BeaconID beaconID) {
if(beaconID != null){
int beaconMinor = beaconID.getMinor();
switch (beaconMinor) {
case 9911: startActivity(i);
break;
case 11904: startActivity(j);
break;
case 27710: startActivity(k);
break;
}
}
}
});
}
}
My onCreate just runs this program, onResume starts looking for beacons, and onPause stops looking.
What I am wondering is if there is a way to extend/pass/run this method in another activity without having to copy it all down again? Or is there a way to have this constantly running in the background and changing activities.
Right now once MainActivity switch to corsi, search_key, or corsi2 it just stays on that activity. Corse, search_key, and corsi2 are empty new activities right now.
Also all beaconDistances does is scan for beacons and returns the closest beacon along with an identification number for that beacon (a minor).