title: Android - Rotate screen programmatically without locking it
body: <p>I'm trying to achieve this behaviour:</p>
  
  <ul>
  <li>When I rotate the device to landscape, the screen does it too.</li>
  <li>To get it back to portrait there are two ways:
  
  <ol>
  <li>Rotating the device</li>
  <li>Clicking on a button that appears only in landscape mode that will rotate the screen back to portrait.</li>
  </ol></li>
  </ul>
  
  <p>The problem:
  The button that puts the screen back to portrait works just fine but then I want to be able to rotate the device to landscape and rotate the screen, but it remains locked in portrait.</p>
  
  <p>The behaviour is like youtube player, where you rotate or click the button to exit fullscreen.</p>
  
  <p>My code for the button:</p>
  
  <pre><code>findViewById(R.id.exit_fs).setOnClickListener(new Button.OnClickListener(){
      @Override
      public void onClick(View arg0) {
          setRequestedOrientation(Build.VERSION.SDK_INT &lt; 9 ?
          ActivityInfo.SCREEN_ORIENTATION_PORTRAIT :
          ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
      }
  });
  </code></pre>
  
  <p>Any ideas?</p>