Prevent Activity from restarting on rotating the screen

android, android-intent, android-layout

Solution

Add this line to your Manifest.xml file, this will prevent of calling `onCreate()` when screen rotates.

<activity android:name=".yourActivity" android:configChanges="keyboardHidden|orientation">

Version above Android 3.2, you also need to add "screenSize":

<activity android:name=".yourActivity" android:configChanges="keyboardHidden|orientation|screenSize">

Problem

My app is a simple form. I use `TableLayout`, and have a lot of rows set to `visibility="gone"`. As user starts filling out the form, more and more rows become visible. But the problem is that the very second screen rotates from portrait to landscape or from landscape to portrait, the whole form resets, and all the fields that were visible become invisible. Is there any way to prevent this from happening? Thanks in advance to anyone who helps :)

Original source

Related problems