Last Updated: February 25, 2016
·
5.929K
· Julio Bêtta

Android webview and device orientation changing

Here's a tipical issue when creating an app with a webview: lose the form state when changing device's orientation. To avoid that, the only thing to do is to add this property to the main activity markup in your AndroidManifest.xml:

android:configChanges="orientation|keyboardHidden|screenSize"

Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project.mobile"
android:versionCode="3"
android:versionName="1.0.1">

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

</manifest>

Believe me, I've lost a few hours to figure this out... Hope it helps!