title: Do something right before Screen Rotation?
body: <p>i want to <code>do_something()</code> whenever the device rotates from Portrait to Landscape.</p>
  
  <p>i have added <code>&lt;activity android:configChanges="orientation" &gt;</code> in my manifest. So <code>onConfigurationChanged()</code> will be called whenever i rotate my device. And it will <em>not</em> re-create the Activity.</p>
  
  <p>In my <code>onConfigurationChanged()</code> function:</p>
  
  <pre><code>@Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
          do_something();
      }
      then_fire_off_the_screen_rotation_as_normal();
      // which means re-start the Activity
      // i expect it will fire off onSaveInstanceState() -&gt; onPause() -&gt; onStop() -&gt; onDestroy() -&gt; onCreate() -&gt; onStart() -&gt; onRestoreInstanceState() -&gt; onResume()
  }
  </code></pre>
  
  <p>My problem is, i dont know what can i do in <code>then_fire_off_the_screen_rotation_as_normal()</code>.</p>
  
  <p>i have tried using <code>setRequestedOrientation()</code> but it seems it is not the function serving this purpose:</p>
  
  <p>When i pass in <code>ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED</code>, <code>ActivityInfo.SCREEN_ORIENTATION_SENSOR</code>, or <code>ActivityInfo.SCREEN_ORIENTATION_USER</code>, the Activity is still <em>not</em> re-started. (Just like not calling.)</p>
  
  <p>When i pass in <code>ActivityInfo.SCREEN_ORIENTATION_NOSENSOR</code>, the orientation sensor turned off. (As it said.)</p>
  
  <p>When i pass in <code>ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE</code>, the Activity was <strong>Force Close</strong> with <code>AndroidRuntime:NullPointerException</code>.</p>
  
  <hr>
  
  <p><em>(Be specific: It is because there are programmatically added Fragments in the Portrait layout, but not in the Landscape layout. In the <code>do_something()</code> function, i will remove those Fragments, as they are not needed in Landscape mode.)</em></p>