-
-
Notifications
You must be signed in to change notification settings - Fork 33
fix(webview): preserve internal WebView state across rotation (#47) #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,8 +96,13 @@ void configureWebview(){ | |
|
|
||
| binding.webview.setWebViewClient(cookieClient); | ||
|
|
||
| binding.webview.loadUrl(startURL); | ||
|
|
||
| if (savedInstanceState != null) { | ||
| // Issue #47: restore the saved WebView state on rotation | ||
| // instead of force-reloading the original URL. | ||
| binding.webview.restoreState(savedInstanceState); | ||
| } else { | ||
|
Comment on lines
+99
to
+103
|
||
| binding.webview.loadUrl(startURL); | ||
| } | ||
|
Comment on lines
+99
to
+105
|
||
|
|
||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebView.restoreState(...)can return null when it can’t restore the state. In that case, this code skipsloadUrl(startURL)and can leave a blank WebView. Capture the return value and fall back toloadUrl(startURL)when restoration fails.