From e6b5e1e68e81c5856798a39b547557d98f43c753 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 7 Feb 2024 17:30:31 +0200 Subject: [PATCH] Reload the url if the state was destroyed --- .../org/wordpress/android/ui/WebViewActivity.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java index b50315129ea7..1999b39538e2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java @@ -100,9 +100,13 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { if (webViewState != null && webViewState.length > WEBVIEW_CHROMIUM_STATE_THRESHOLD) { outState.remove(WEBVIEW_CHROMIUM_STATE); + // Save the URL so it can be restored later + String url = mWebView.getUrl(); + outState.putString(URL, url); + // Track the error to better understand the root of the issue Map properties = new HashMap<>(); - properties.put(URL, mWebView.getUrl()); + properties.put(URL, url); AnalyticsTracker.track(AnalyticsTracker.Stat.WEBVIEW_TOO_LARGE_PAYLOAD_ERROR, properties); } super.onSaveInstanceState(outState); @@ -114,7 +118,14 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { @Override protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); - mWebView.restoreState(savedInstanceState); + if (savedInstanceState.containsKey(WEBVIEW_CHROMIUM_STATE)) { + mWebView.restoreState(savedInstanceState); + } else { + String url = savedInstanceState.getString(URL); + if (url != null) { + mWebView.loadUrl(url); + } + } } @Override