title: Android SensorListener Deprecated
body: <p>I am trying to change the following code to use a compass, however, I am having trouble, I tried to use SensorEventListener, but I failed. Is there any tutorial that I may follow? Any help would be greatly appreciated.</p>
  
  <pre class="lang-js prettyprint-override"><code>private static SensorListener orientationListener;
      private static boolean isTrackingOrientation = false;
  
      @Override
      public void onCreate(Bundle icicle) {
  
      super.onCreate(icicle);
          setContentView(R.layout.main);
  
          orientationListener = new SensorListener() {
              public void onSensorChanged(int s, float v[]) {
                  float northDirection = v[android.hardware.SensorManager.DATA_X];
                  ((QiblaCompassView)findViewById(R.id.qibla_compass)).setDirections(northDirection, VARIABLE.qiblaDirection);
  
              }
              public void onAccuracyChanged(int s, int a) {
              }
          }; 
      }
  
      @Override
      public void onResume() {
          startTrackingOrientation();
          super.onResume();
      }
      @Override
      public void onPause() {
          stopTrackingOrientation();
          super.onPause();
      }
  
      private void startTrackingOrientation() {
          if(!isTrackingOrientation) isTrackingOrientation = ((SensorManager)getSystemService(SENSOR_SERVICE)).registerListener(orientationListener, android.hardware.SensorManager.SENSOR_ORIENTATION);
      }
      private void stopTrackingOrientation() {
          if(isTrackingOrientation) ((SensorManager)getSystemService(SENSOR_SERVICE)).unregisterListener(orientationListener);
          isTrackingOrientation = false;
      }
  </code></pre>