aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-03-17 13:22:26 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-03-17 13:22:26 +0000
commit59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c (patch)
treee5889079fccb640a1ac6bdd73eb3ba99cd9860af
parentb4915859da8463d4ea3cca960f1bf1124c4bd591 (diff)
downloadinfinity-for-reddit-59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c.tar
infinity-for-reddit-59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c.tar.gz
infinity-for-reddit-59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c.tar.bz2
infinity-for-reddit-59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c.tar.lz
infinity-for-reddit-59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c.tar.xz
infinity-for-reddit-59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c.tar.zst
infinity-for-reddit-59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c.zip
Prevent WebView from reloading the website after orientation change in WebViewActivity.
-rw-r--r--app/src/main/AndroidManifest.xml3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java19
2 files changed, 19 insertions, 3 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 71359562..05cd4a65 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -76,7 +76,8 @@
android:name=".activities.WebViewActivity"
android:label=""
android:parentActivityName=".activities.MainActivity"
- android:theme="@style/AppTheme.NoActionBar" />
+ android:theme="@style/AppTheme.NoActionBar"
+ android:configChanges="orientation|screenSize" />
<activity
android:name=".activities.SuicidePreventionActivity"
android:parentActivityName=".activities.MainActivity"
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java
index 37ac9b9b..c21ac456 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java
@@ -19,6 +19,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
+import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -79,8 +80,10 @@ public class WebViewActivity extends BaseActivity {
webView.getSettings().setDomStorageEnabled(true);
url = getIntent().getDataString();
- toolbar.setTitle(url);
- webView.loadUrl(url);
+ if (savedInstanceState == null) {
+ toolbar.setTitle(url);
+ webView.loadUrl(url);
+ }
WebViewClient client = new WebViewClient() {
@Override
@@ -177,4 +180,16 @@ public class WebViewActivity extends BaseActivity {
}
return super.onKeyDown(keyCode, event);
}
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ webView.saveState(outState);
+ }
+
+ @Override
+ protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ webView.restoreState(savedInstanceState);
+ }
} \ No newline at end of file