@Override
  protected void onStop() {
    super.onStop();

    if (screenWakeLock != null) {
      screenWakeLock.release();
      screenWakeLock = null;
    }

    // remove the flag that disables the screen dimming
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // remove use of the location listener
    locationManager.removeUpdates(locationListener);

    // turn stabilization back on
    StabilizationCommand.sendCommand(mRobot, true);

    // turn rear light off
    FrontLEDOutputCommand.sendCommand(mRobot, 0.0f);

    // unregister the async data listener to prevent a memory leak.
    DeviceMessenger.getInstance().removeAsyncDataListener(mRobot, mDataListener);

    // stop the streaming data when we leave
    SetDataStreamingCommand.sendCommand(
        mRobot, 0, 0, SetDataStreamingCommand.DATA_STREAMING_MASK_OFF, 0);

    // pause here for a tenth of a second to allow the previous commands to go through before we
    // shutdown
    // the connection to the ball
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // disconnect from the ball
    RobotProvider.getDefaultProvider().removeAllControls();

    // mRobot = null;
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == STARTUP_ACTIVITY && resultCode == RESULT_OK) {
      // get the connected robot
      final String robot_id = data.getStringExtra(StartupActivity.EXTRA_ROBOT_ID);
      Log.d(TAG, "Hi, there robot " + robot_id);
      if (robot_id != null && !robot_id.equals("")) {
        mRobot = RobotProvider.getDefaultProvider().findRobot(robot_id);

        StabilizationCommand.sendCommand(mRobot, false);
        FrontLEDOutputCommand.sendCommand(mRobot, 0.5f);
        startStreaming();
      }
    }

    // start blinking
    // blink(false);
    RGBLEDOutputCommand.sendCommand(mRobot, 0, 0, 0);
  }