title: How do you properly handle device orientation from an android native only application?
body: <p>The objective is to make a simple 2d arrow compass application like the one from the book <a href="https://rads.stackoverflow.com/amzn/click/com/0596804822" rel="nofollow noreferrer" rel="nofollow noreferrer">iPhone 3D Programming</a> <a href="http://examples.oreilly.com/9780596804831/readme.html#HelloArrow" rel="nofollow noreferrer">here</a> that rotates smoothly in response to orientation changes.</p>
  
  <p>AndroidManifest.xml (Subscribe to orientation changes)</p>
  
  <pre><code>&lt;activity android:name="android.app.NativeActivity"
   android:label="@string/app_name"
   android:configChanges="orientation|keyboardHidden"&gt;
  </code></pre>
  
  <p>AndroidApp.cpp (Get angle of rotation)</p>
  
  <pre><code>void AndroidApp::handleCmd (int32_t cmd) {
  switch (cmd) {
      case APP_CMD_CONFIG_CHANGED:
         // Your code here
      break;
    }
  }
  </code></pre>
  
  <p>RenderingEngine.cpp (Store angle to rotate the arrow when rendering the scene)</p>
  
  <pre><code>    void RenderingEngine::OnRotate(DeviceOrientation orientation)
      {
         float angle = 0;
  
         switch (orientation) {
            case DeviceOrientationLandscapeLeft:
               angle = 270;
               break;
  
            case DeviceOrientationPortraitUpsideDown:
               angle = 180;
               break;
  
            case DeviceOrientationLandscapeRight:
               angle = 90;
               break;
         }
  
         m_desiredAngle = angle;
      }
  </code></pre>