fix(help): preserve WebView state across home/resume (#136)#155
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes the Help WebView navigation/scroll state being lost when the app is backgrounded (Home) and resumed, aligning behavior with Issue #136 by restoring the WebView snapshot instead of reloading the start page on every onResume.
Changes:
- Load the help start page only on fresh activity creation; otherwise restore the
WebViewstate fromsavedInstanceState. - Persist
WebViewstate viaonSaveInstanceState()and stop clearing history/reloading inonResume().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (savedInstanceState != null) { | ||
| helpBrowser.restoreState(savedInstanceState); | ||
| } else { | ||
| Intent intent = this.getIntent(); | ||
| startPage = assetPrefix + intent.getStringExtra("page"); | ||
| helpBrowser.loadUrl(startPage); | ||
| } |
There was a problem hiding this comment.
WebView.restoreState() can return null when there’s no WebView state in the Bundle. If that happens, the current code won’t load the start page and the WebView may stay blank. Consider checking the return value and falling back to loading the intent page when restore fails.
| Intent intent = this.getIntent(); | ||
| startPage = assetPrefix + intent.getStringExtra("page"); | ||
| helpBrowser.loadUrl(startPage); |
There was a problem hiding this comment.
startPage is now only assigned and immediately used in this branch. Consider making it a local variable (or removing the field entirely) to avoid keeping an unused instance field that can be null in the restored-state path.
Closes #136.
The Help WebView lost its state on every Home press because
onResumeunconditionally cleared history and reloaded the start page. Returning to the app dropped the user back athelpindex.htmlregardless of what they had been reading or how far they had scrolled.This change loads the start page once when the activity is created, persists the WebView snapshot in
onSaveInstanceState, and restores it when the activity is recreated.onResumeno longer touches navigation state.