Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update April 2013: Don't do this. It wasn't a good idea in 2009 when I first answered the question and it really isn't a good idea now. See this answer by hackbod for reasons:</strong> </p> <p><a href="https://stackoverflow.com/questions/5335665/avoid-reloading-activity-with-asynctask-on-orientation-change-in-android/5336057#5336057">Avoid reloading activity with asynctask on orientation change in android</a></p> <p>Add <code>android:configChanges="keyboardHidden|orientation"</code> to your AndroidManifest.xml. This tells the system what configuration changes you are going to handle yourself - in this case by doing nothing.</p> <pre><code>&lt;activity android:name="MainActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation"&gt; </code></pre> <p>See Developer reference <a href="http://developer.android.com/reference/android/R.attr.html#configChanges" rel="noreferrer">configChanges</a> for more details.</p> <p>However, your application can be interrupted at any time, e.g. by a phone call, so you really should add code to save the state of your application when it is paused.</p> <p><strong>Update:</strong> As of Android 3.2, you also need to add "screenSize":</p> <pre><code>&lt;activity android:name="MainActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize"&gt; </code></pre> <p>From Developer guide <a href="http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange" rel="noreferrer"> Handling the Configuration Change Yourself</a></p> <blockquote> <p>Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must declare <code>android:configChanges="orientation|screenSize"</code>. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).</p> </blockquote>
 

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