title: Is it possible to get Android accelerometer values inside onCreate method?
body: <p>Is it possible to get Android accelerometer values inside <code>onCreate</code> method? I want it,
  so as to make some initializations after reading them. So far, I have registered
  a sensor listener to get those values when they change through the <a href="http://developer.android.com/reference/android/hardware/SensorListener.html#onSensorChanged%28int,%20float%5B%5D%29" rel="nofollow">onSensorChanged</a>
  callback. I have 3 float attributes (<em>lastx</em>, <em>lasty</em> and <em>lastz</em>) initialized to -1, so as to store the accelerometer values there upon change. In <code>onCreate</code> method, after registering my sensor listener, I am trying to check these values, but they are always equal to -1. Is there a way to get these values inside the <code>onCreate</code> method?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class MainActivity extends Activity implements SensorEventListener {
      private SensorManager sensorManager;
  
      TextView textView;
      StringBuilder builder = new StringBuilder();
      float lastx = -1;
      float lasty = -1;
      float lastz = -1;
  
      @Override
      public void onCreate(Bundle savedInstanceState){
  
          super.onCreate(savedInstanceState);
          textView = new TextView(this);
  
          SensorManager manager = (SensorManager) 
                       getSystemService(Context.SENSOR_SERVICE);
  
          Sensor accelerometer = manager.getDefaultSensor(
                                       Sensor.TYPE_ACCELEROMETER);
  
          if(!manager.registerListener(this, accelerometer,
                                       SensorManager.SENSOR_DELAY_GAME)){
          Log.d("ERROR: ", "NO accelerometer found!");
          }
  
          setContentView(textView);
          builder.setLength(0);
  
          builder.append(
             "X " + this.lastx + "\nY " + this.lasty + "\nZ " + this.lasty);
          textView.setText(builder.toString());
  
           Log.d(" * accelerometer values:",
              "X: " + this.lastx+", Y: " + this.lasty + ", Z: " + this.lastz);
  
      }
  
      public void onAccuracyChanged(Sensor sensor,int accuracy){
  
      }
  
      public void onSensorChanged(SensorEvent event){
  
              // check sensor type
              if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
  
                   // assign directions
                   float x=event.values[0];
                   float y=event.values[1];
                   float z=event.values[2];
  
                   this.lastx = x;
                   this.lasty = y;
                   this.lastz = z;
  
                   // builder.setLength(0);
                   // builder.append("X " + x + "\nY " + y + "\nZ " + z);
                   // textView.setText(builder.toString());
        }
    }
  }
  </code></pre>