title: Android: starting activity landscape wrong orientation
body: <p>I'm facing a strange problem: i have an activity wich launches another activity when orientation changes to landscape. the problem is that the new activity comes in the reverse position when i turn my device clockwise.</p>
  
  <p>Some screenshots to understand...</p>
  
  <p>FirstActivity (runs in portrait mode):
  <img src="https://i.stack.imgur.com/G5D9R.png" alt="enter image description here"></p>
  
  <p>When i turn the device counterclockwise my second activity is launched and it all works great:
  <img src="https://i.stack.imgur.com/TqCbI.png" alt="enter image description here"></p>
  
  <p>If i turn my device in portrait orientation the first activity gets called and it's all ok: i can go on turning it again and again and it always works.
  The problem is that when i turn my device clockwise i get this:
  <img src="https://i.stack.imgur.com/AbIFP.png" alt="enter image description here"></p>
  
  <p>Here' the code:</p>
  
  <p>first activity (glanceActivity):</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_glance_landscape);
  
      setOrientationChangeListener();
  }
  
  private void setOrientationChangeListener() {
  
      mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){
  
          long changeStart = 0;
  
          @Override
          public void onOrientationChanged(int arg0) {
  
              if (arg0 &gt; 80 &amp;&amp; arg0 &lt; 280) {
                  if(changeStart == 0) {
                      changeStart = System.currentTimeMillis();
                  }
                  else if ((System.currentTimeMillis() - changeStart) &gt; 1500) {
                      launchLandscapeActivity();
                      changeStart = 0;
                  }
              }
              else {
                  changeStart = 0;
              }
          }
      };
  
      if (mOrientationEventListener.canDetectOrientation()){
          mOrientationEventListener.enable();
      }
      else{
          finish();
      }
  }
  
  private void launchLandscapeActivity() {
      mOrientationEventListener.disable();
      Intent intent = new Intent(GlanceActivity.this, GlanceLandscapeActivity.class);
      startActivity(intent);
      finish();
  }
  </code></pre>
  
  <p>And here's my second activity (GlanceLandscapeActivity):</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_glance_landscape);
  
      setOrientationChangeListener();
  }
  
  private void setOrientationChangeListener() {
  
      mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){
  
         long changeStart = 0;
  
         @Override
         public void onOrientationChanged(int arg0) {
  
          if ((arg0 &lt;= 360 &amp;&amp; arg0 &gt; 280) || (arg0 &gt;= 0 &amp;&amp; arg0 &lt; 80)) {
              if(changeStart == 0) {
                  changeStart = System.currentTimeMillis();
              }
              else if ((System.currentTimeMillis() - changeStart) &gt; 1500) {
                  launchPortraitActivity();
                  changeStart = 0;
              }
          }
          else {
              changeStart = 0;
          }
      }
  };
  
  if (mOrientationEventListener.canDetectOrientation()){
      mOrientationEventListener.enable();
  }
  else{
      finish();
  }
  }
  
  private void launchPortraitActivity() {
      mOrientationEventListener.disable();
      Intent intent = new Intent(GlanceLandscapeActivity.this, GlanceActivity.class);
      startActivity(intent);
      finish();
  }
  </code></pre>
  
  <p>EDIT: I forgot to add the declaration in the manifest.xml :</p>
  
  <pre><code>&lt;activity
        android:name=".GlanceActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:screenOrientation="portrait"
        android:label="@string/title_activity_glance"
        android:theme="@style/sectionsTheme" &gt;
  &lt;/activity&gt;
  &lt;activity
        android:name=".GlanceLandscapeActivity"
        android:label="@string/title_activity_glance_landscape"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:screenOrientation="landscape"
        android:theme="@android:style/Theme.Holo.Light.NoActionBar" &gt;
  &lt;/activity&gt;
  </code></pre>