title: Printing accelerometer data every 1 second
body: <p>I am desiging an app that displays gyroscope and accelerometer readings every second. This is the code I use
  I have a start button, setting time to current in the OnCreate method.</p>
  
  <pre><code>start.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
  
              time = System.currentTimeMillis();
              mSensorManager.registerListener(MainActivity.this, mAccelerometerSensor, SensorManager.SENSOR_DELAY_GAME);
              mSensorManager.registerListener(MainActivity.this, mGyroscopeSensor, SensorManager.SENSOR_DELAY_GAME);
  
          }
  </code></pre>
  
  <p>And then in onSensorChanged:</p>
  
  <pre><code>   public void onSensorChanged(SensorEvent event) {
          long currentTime = System.currentTimeMillis();
          if (currentTime - time &gt; 1000) {
  
          time = currentTime;
          switch (event.sensor.getType()) {
  
  
              case Sensor.TYPE_GYROSCOPE: {
                  mXGyrValueText.setText(String.format("%1.3f",
                          event.values[SensorManager.DATA_X]));
                  mYGyrValueText.setText(String.format("%1.3f",
                          event.values[SensorManager.DATA_Y]));
                  mZGyrValueText.setText(String.format("%1.3f",
                          event.values[SensorManager.DATA_Z]));
  
                  break;
              }
  
  
              case Sensor.TYPE_LINEAR_ACCELERATION: {
                  mXAccValueText.setText(String.format("%1.3f",
                          event.values[SensorManager.DATA_X]));
                  mYAccValueText.setText(String.format("%1.3f",
                          event.values[SensorManager.DATA_Y]));
                  mZAccValueText.setText(String.format("%1.3f",
                          event.values[SensorManager.DATA_Z]));
  
  
                  break;
              }
  
          }
      }
  </code></pre>
  
  <p>This works fine for gyroscope, however accelerometer readings are updating at random time period. What is the problem? Perhaps, there is a better solution?</p>