title: Handle screen orientation changes when there are AsyncTasks running
body: <p>I've been bugged by this for a while. How do I properly handle screen orientation changes while I have a separate <code>Thread</code> / <code>AsyncTask</code> running? Currently, I have</p>
  
  <pre><code>android:configChanges="orientation|keyboard|keyboardHidden"
  </code></pre>
  
  <p>in my <code>AndroidManifest.xml</code>, but that is <a href="http://developer.android.com/guide/topics/manifest/activity-element.html#config" rel="nofollow noreferrer">not really encouraged</a>:</p>
  
  <blockquote>
    <p><strong>Note:</strong> Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.</p>
  </blockquote>
  
  <p>Also, in the <strong>2.3 emulator</strong>, it works when switching to <code>landscape</code>, but switching back to <code>portrait</code> fails.</p>
  
  <p>Now, the reason why I use <code>configChanges</code> is because when the user switches orientation, I might have an <code>AsyncTask</code> running, doing some network traffic, and I don't want it stopped.</p>
  
  <p>Is there any other way of doing this, or is there a way of fixing 2.3 to switch back to portrait?</p>
  
  <p>I know about <code>onRetainNonConfigurationInstance</code>, but I'm not sure it would be a good idea to "save" the <code>AsyncTask</code> instance, mainly because the class that extends <code>AsyncTask</code> is not static (so it is tied to the <code>Activity</code>) -- and it needs to be, because in <code>onPostExecute()</code> it calls methods from the <code>Activity</code> instance.</p>