Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable screen rotation at runtime on Android
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload