title: Synchronize accelerometer and Gyroscope / Android
body: <p>I am developing a mobile application under android and I need to retrieve the data from the accelerometer and gyroscope at exactly the same time ie I need to synchronize the two sensors to simultaneously read their values . I need to use a Service (not an Activity) but the value of the two event.timestamp are completely different.</p>
  
  <pre><code>public void onSensorChanged(SensorEvent event) {
  
  
      if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
          xa =event.values[0] ;
          ya =event.values[1] ;
          za =event.values[2] ;
          ta= event.timestamp;
  
      }
  
      if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
          xg = event.values[0];
          yg = event.values[1];
          zg = event.values[2];
          tg = event.timestamp;
     }
  </code></pre>
  
  <p>Thank you.</p>