Example #1
0
  /** Handles the hardware back-button press */
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    Utilities.LogInfo("KeyDown - " + String.valueOf(keyCode));

    if (keyCode == KeyEvent.KEYCODE_BACK && Session.isBoundToService()) {
      StopAndUnbindServiceIfRequired();
    }

    return super.onKeyDown(keyCode, event);
  }
Example #2
0
  /** Stops the service if it isn't logging. Also unbinds. */
  private void StopAndUnbindServiceIfRequired() {
    Utilities.LogDebug("GpsMainActivity.StopAndUnbindServiceIfRequired");
    if (Session.isBoundToService()) {
      unbindService(gpsServiceConnection);
      Session.setBoundToService(false);
    }

    if (!Session.isStarted()) {
      Utilities.LogDebug("StopServiceIfRequired - Stopping the service");
      // serviceIntent = new Intent(this, GpsLoggingService.class);
      stopService(serviceIntent);
    }
  }