Disable screen rotation at runtime on Android
<pre><code>public class testScreenRotation extends Activity {
/** Called when the activity is first created. */

private int mRuntimeOrientation;
   private boolean mDisableScreenRotation=true;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mRuntimeOrientation = this.getScreenOrientation();
    setContentView(R.layout.main);


}
protected int getScreenOrientation() {
/*
    Display display = getWindowManager().getDefaultDisplay();
    int orientation = display.getOrientation();

    if (orientation == Configuration.ORIENTATION_UNDEFINED) {
       orientation = getResources().getConfiguration().orientation;

       if (orientation == Configuration.ORIENTATION_UNDEFINED) {
          if (display.getWidth() == display.getHeight())
             orientation = Configuration.ORIENTATION_SQUARE;
          else if(display.getWidth() &lt; display.getHeight())

             orientation = Configuration.ORIENTATION_PORTRAIT;
          else
             orientation = Configuration.ORIENTATION_LANDSCAPE;
          }
       }


    return orientation;
  */
    return Configuration.ORIENTATION_PORTRAIT;
 }
@Override
public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
       if (mDisableScreenRotation) {
             super.onConfigurationChanged(newConfig);
             this.setRequestedOrientation(mRuntimeOrientation);
          } else {
             mRuntimeOrientation = this.getScreenOrientation();
             super.onConfigurationChanged(newConfig);
          }
       }

}
</code></pre>

<p>my app as above ,and add android:configChanges="orientation" in the xml.when  my app start my screen is PORTRAIT,i press ctrl+F12,the screen also roate,the screen is LANDSCAPE,second i  press ctrl+F12,the screen also roate,the screen is PORTRAIT,then i  press ctrl+F12,the screen keep PORTRAIT. so i press again,the screen  keep PORTRAIT. my question is that why my screen not keep  PORTRAIT when the app start.</p>

<p>Edit:i want to use code to control the screen roate, if i can do this?</p>
