Allow / Deny screen rotation in onConfigurationChange - Android
<p>I have an activity that handles 2 modes of display : </p>

<ol>
<li>Normal mode : The screen should not rotate, always in portrait mode.</li>
<li>Fullscreen mode : The screen could be portrait or landscape</li>
</ol>

<p>I have only 1 activity to handle the 2 modes with : </p>

<ul>
<li>boolean variable "<strong><em>isFullscreen</em></strong>" that indicates either the activity is in fullscreen mode or normal mode.</li>
<li><em><strong>changeMode()</em></strong> a function that calls "<strong><em>setContentView</em></strong>" to switch the xml layout proper to the current mode
<ul>
<li>in the manifest file, i have <strong><em>android:configChanges="screenSize|orientation"</em></strong> to let the activity handle configuration change</li>
</ul></li>
<li>overriding the method <strong><em>onConfigurationChanged</em></strong>.</li>
</ul>

<p>I've tried this : </p>

<pre><code>@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (isFullscreen) {
        super.onConfigurationChanged(newConfig);
    } else {
        super.onConfigurationChanged(newConfig);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}
</code></pre>

<p>but in this case : the screet does not rotate in any mode (not even in fullscreen mode, with isFullscreen et to true)</p>

<pre><code>@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (isFullscreen) {
        super.onConfigurationChanged(newConfig);
    } else {

    }
}
</code></pre>

<p>but i got Super Not Called exception or something like that (i was thinking if i don't call super in the case of normal mode, it would not rotate the screen)</p>

<p>and finally i've tried this : </p>

<pre><code>@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (isFullscreen) {
        super.onConfigurationChanged(newConfig);
    } else {
        newConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
        super.onConfigurationChanged(newConfig);
    }
}
</code></pre>
