diff options
author | Docile-Alligator <chineseperson5@gmail.com> | 2022-03-17 13:22:26 +0000 |
---|---|---|
committer | Docile-Alligator <chineseperson5@gmail.com> | 2022-03-17 13:22:26 +0000 |
commit | 59ed4c53ffa036d3fd89d8c9d652c0c88fa3d95c (patch) | |
tree | e5889079fccb640a1ac6bdd73eb3ba99cd9860af /app/src/main | |
parent | b4915859da8463d4ea3cca960f1bf1124c4bd591 (diff) | |
download | infinity-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.
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java | 19 |
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 |