title: Handling activity rotating in Android
body: <p>I need to apply different layouts for portrait and landscape orientations of my activity. Besides, I need to show alert if orientation is portrait.</p>
  
  <p>I have specified <code>android:configChanges="orientation|keyboardHidden"</code> in AndroidManifest. I also override onConfigurationChanged method like this:</p>
  
  <pre><code>@Override
  public void onConfigurationChanged(Configuration newConfig)
  {
      Log.d("tag", "config changed");
      super.onConfigurationChanged(newConfig);
  
      int orientation = newConfig.orientation;
      if (orientation == Configuration.ORIENTATION_PORTRAIT)
          Log.d("tag", "Portrait");
      else if (orientation == Configuration.ORIENTATION_LANDSCAPE)
          Log.d("tag", "Landscape");
      else
          Log.w("tag", "other: " + orientation);
  
      ....
  }
  </code></pre>
  
  <p>While rotating from landscape to portrait log looks like:</p>
  
  <pre><code>config changed
  Portrait
  </code></pre>
  
  <p>But while changing from portrait to landscape it looks like</p>
  
  <pre><code>config changed
  Portrait
  config changed
  Landscape
  </code></pre>
  
  <p>Why onConfigurationChanged is called twice? How can I avoid it?</p>