Android - Preventing WebView reload on Rotate
I think the main problem is that you call web.loadUrl(webURL); also when savedInstanceState != null
EDIT
Try:
if (savedInstanceState == null)
{
web.loadUrl(webURL);
}
EDIT2: You also need the onSaveInstanceState and onRestoreInstanceState override.
@Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
web.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
web.restoreState(savedInstanceState);
}
Note: Please also add in your AndroidManifest.xml in your Activity
android:configChanges="orientation|screenSize"
Thanks
How to prevent web view from reloading when rotated
You can make changes in your manifest file as follows -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myworldrules.apps.lifehacks">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
How to prevent WebView auto refresh when screen rotation
Highlighting @kirgy comment, You have to add orientation|screenSize
to your manifest if your API > 3.2 , It wont work without it in some cases.
Related Topics
Variable Length (Dynamic) Arrays in Java
Java Gotoxy(X,Y) for Console Applications
Intellij Fat One Jar Artifact Does Not Generate a Working Output
How to Access a Folder Inside of a Resource Folder from Inside My Jar File
"Loadstylesheetunprivileged" Error When Trying to Use CSS Stylesheet with Javafx
Preemptive Basic Auth with Httpurlconnection
Android How to Listen for Volume Button Events
How to Properly Implement Parcelable with an Arraylist<Parcelable>
How to Set Up Intellij Idea for Android Applications
How to Kill Currently Running Task in Android
Collections Sort(List<T>,Comparator<? Super T>) Method Example
Java.Sql.Sqlexception: Column Count Doesn't Match Value Count at Row 1
Differencebetween ? and Object in Java Generics
Javafx - How to Create a Thin Menubar
String.Equals() with Multiple Conditions (And One Action on Result)