title: Step counter in android studio keeps restarting, from like 15 steps to 1-2
body: <p>I'm trying to do a step counter program that records your steps and multiplies by 0.04 to get your calories. </p>
  
  <p>The problem is that the step counter keeps refreshing without clicking on the reset button. It goes to 12 steps, then goes to 0.</p>
  
  <p>I have no clue what to try. I am new in android and I don't really know how to mess with sensors.</p>
  
  <pre><code>package igor.finaltp;
  
  
  import android.content.Context;
  import android.hardware.Sensor;
  import android.hardware.SensorEvent;
  import android.hardware.SensorEventListener;
  import android.hardware.SensorManager;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity implements SensorEventListener {
  
      TextView tv_steps;
      TextView tv_calories;
      Sensor mStepDetectorSensor;
      SensorManager sensorManager;
      boolean running = false;
      Button btn_reset;
      int pace = 0;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          tv_steps = (TextView) findViewById(R.id.tv_steps);
          sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
          mStepDetectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
          sensorManager.registerListener(this, mStepDetectorSensor, SensorManager.SENSOR_DELAY_NORMAL);
          btn_reset = (Button) findViewById(R.id.btn_reset);
          btn_reset.setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View view) {
  
                      pace = 0;
                      tv_steps.setText("0");
                      tv_calories.setText("0");
                      return true;
              }
          });
          tv_calories = (TextView) findViewById(R.id.tv_calories);
  
      }
  
      @Override
      protected void onResume(){
          super.onResume();
          //ao entrar na app ele escuta o sensor, passando a activity, o sensor e o tempo de intervalo
          sensorManager.registerListener(this, mStepDetectorSensor, SensorManager.SENSOR_DELAY_NORMAL);
      }
  
  
  
      @Override
      protected void onStop() {
          super.onStop();
          //ao sair do app ele para de escutar o sensor passando a actovity e o sensor
          sensorManager.unregisterListener(this, mStepDetectorSensor);
      }
  
      @Override
      public void onSensorChanged(SensorEvent sensorEvent) {
          Sensor sensor = sensorEvent.sensor;
  
          if(sensor.getType() == Sensor.TYPE_STEP_DETECTOR){
              pace++;
              tv_steps.setText("" + pace);
  
              double calories = pace*0.04;
              tv_calories.setText(String.format("%.2f", (calories)) + " Kcal lost");
          }
      }
  
      @Override
      public void onAccuracyChanged(Sensor sensor, int i) {
  
      }
  }
  </code></pre>
  
  <p>I expect somewhere around 10 steps when I walk for 10-15 steps
  I get the right amount of steps but it refreshes somehow to 0 steps</p>