Disable orientation but detect orientation
<p>I've an activity. This activity works in portrait mode or landscape mode. In landcape mode, i load a new layout to show a graph. 
To detect orientation, i set up this in my manifest :</p>

<pre><code>android:screenOrientation="sensor" android:configChanges="orientation"
</code></pre>

<p>It works perfectly because when i flip my phone, the new layout is loaded. But, in the lanscape mode, the user can disable/enable the rotation with a button (it's a switcher). </p>

<p>I wrote this code :</p>

<pre><code>public void onConfigurationChanged(Configuration pNewConfig) {
    Log.v(DEBUG_TAG, "Current configuration changes");

    if (pNewConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Log.v(DEBUG_TAG, "Screen orientation : LANDSCAPE");
        if (pNewConfig.orientation != mCurrentOrientation) {
            initTestLandscape();
            mCurrentOrientation = pNewConfig.orientation;
        }
    } else {
        Log.v(DEBUG_TAG, "Screen orientation : PORTRAIT");
        if (!mIsLandscapeLocking
                &amp;&amp; pNewConfig.orientation != mCurrentOrientation) {
            initTestPortrait();
            mCurrentOrientation = pNewConfig.orientation;
        }
    }
    super.onConfigurationChanged(pNewConfig);
}
</code></pre>

<p>This code works but when the user is in landscape mode and flip the phone to back in portrait mode but the lock is up, the lanscape layout flip in portrait mode and i doesn't want that !</p>

<p>I've added </p>

<pre><code>setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
</code></pre>

<p>but this code disable the method onConfigurationChanged and i can't detect if the user flip again this phone...</p>

<p>Can you help me ?</p>
