public void run() {
          if (service != null && service.isRunning() && service.queueEmpty()) {
            queueCommands();

            double lat = 0;
            double lon = 0;
            double alt = 0;
            final int posLen = 7;
            if (mGpsIsStarted && mLastLocation != null) {
              lat = mLastLocation.getLatitude();
              lon = mLastLocation.getLongitude();
              alt = mLastLocation.getAltitude();

              StringBuilder sb = new StringBuilder();
              sb.append("Lat: ");
              sb.append(String.valueOf(mLastLocation.getLatitude()).substring(0, posLen));
              sb.append(" Lon: ");
              sb.append(String.valueOf(mLastLocation.getLongitude()).substring(0, posLen));
              sb.append(" Alt: ");
              sb.append(String.valueOf(mLastLocation.getAltitude()));
              gpsStatusTextView.setText(sb.toString());
            }
            if (prefs.getBoolean(ConfigActivity.UPLOAD_DATA_KEY, false)) {
              // Upload the current reading by http
              final String vin = prefs.getString(ConfigActivity.VEHICLE_ID_KEY, "UNDEFINED_VIN");
              Map<String, String> temp = new HashMap<String, String>();
              temp.putAll(commandResult);
              ObdReading reading =
                  new ObdReading(lat, lon, alt, System.currentTimeMillis(), vin, temp);
              new UploadAsyncTask().execute(reading);

            } else if (prefs.getBoolean(ConfigActivity.ENABLE_FULL_LOGGING_KEY, false)) {
              // Write the current reading to CSV
              final String vin = prefs.getString(ConfigActivity.VEHICLE_ID_KEY, "UNDEFINED_VIN");
              Map<String, String> temp = new HashMap<String, String>();
              temp.putAll(commandResult);
              ObdReading reading =
                  new ObdReading(lat, lon, alt, System.currentTimeMillis(), vin, temp);
              myCSVWriter.writeLineCSV(reading);
            }
            commandResult.clear();
          }
          // run again in period defined in preferences
          new Handler().postDelayed(mQueueCommands, ConfigActivity.getObdUpdatePeriod(prefs));
        }
  private void stopLiveData() {
    Log.d(TAG, "Stopping live data..");

    gpsStop();

    doUnbindService();
    endTrip();

    releaseWakeLockIfHeld();
    final String devemail = prefs.getString(ConfigActivity.DEV_EMAIL_KEY, null);
    if (devemail != null) {
      DialogInterface.OnClickListener dialogClickListener =
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                  ObdGatewayService.saveLogcatToFile(getApplicationContext(), devemail);
                  break;

                case DialogInterface.BUTTON_NEGATIVE:
                  // No button clicked
                  break;
              }
            }
          };
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder
          .setMessage("Where there issues?\nThen please send us the logs.\nSend Logs?")
          .setPositiveButton("Yes", dialogClickListener)
          .setNegativeButton("No", dialogClickListener)
          .show();
    }

    if (myCSVWriter != null) {
      myCSVWriter.closeLogCSVWriter();
    }
  }