Skip to content

Commit

Permalink
Reload the url if the state was destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonis Lilis committed Feb 7, 2024
1 parent 13a66d4 commit e6b5e1e
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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);
Expand All @@ -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
Expand Down

0 comments on commit e6b5e1e

Please sign in to comment.