Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I prevent Android Activity from briefly entering portrait mode when I have specified landscape?
    primarykey
    data
    text
    <p>I have specified my Activity should be fixed to landscape, which works most of the time. <strong><em>Specifically, when the Activity is already running, and I launch a new instance of it from Eclipse</em></strong>, the Activity starts in Portrait and immediately changes to Landscape--but not before the View has already been told it was Portrait. <strong><em>So my View is initialized as Portrait, but gets a surfaceChanged immediately.</em></strong></p> <p>I have the following specified in my manifest:</p> <pre><code> &lt;activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" </code></pre> <p>I have also tried:</p> <pre><code>setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); </code></pre> <p>When I was targeting API level 7, I believe this worked fine. Now I target API level8, and a strange quirk has appeared.</p> <p>In the oncreate method, the value of:</p> <pre><code>getResources().getConfiguration().orientation </code></pre> <p>is:</p> <pre><code>Configuration.ORIENTATION_PORTRAIT </code></pre> <p>Immediately after creating the Activity, the orientation is changed to Landscape, I receive a <code>surfacechanged</code>, and I can "fix" everything. But why is it ever portrait?</p> <p>I suspect it has to do with the fact that the application is autorotated as it launches from a portrait screen. It seems bizarre that the application, which has been instructed to NEVER be in portrait, starts that way, and then quickly changes.</p> <p>But, is there a way to not allow it to ever be in portrait?</p> <p>I put this in my Activity's <code>onCreate</code>:</p> <pre><code>while (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } </code></pre> <p>This resulted in it getting stuck there forever :)</p>
    singulars
    1. This table or related slice is empty.
    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