Skip to content

fix(help): preserve WebView state across home/resume (#136)#155

Open
jim-daf wants to merge 1 commit into
servalproject:developmentfrom
jim-daf:fix/issue-136-help-webview-state
Open

fix(help): preserve WebView state across home/resume (#136)#155
jim-daf wants to merge 1 commit into
servalproject:developmentfrom
jim-daf:fix/issue-136-help-webview-state

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented Apr 25, 2026

Closes #136.

The Help WebView lost its state on every Home press because onResume unconditionally cleared history and reloaded the start page. Returning to the app dropped the user back at helpindex.html regardless 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. onResume no longer touches navigation state.

if (savedInstanceState != null) {
    helpBrowser.restoreState(savedInstanceState);
} else {
    Intent intent = this.getIntent();
    startPage = assetPrefix + intent.getStringExtra("page");
    helpBrowser.loadUrl(startPage);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (helpBrowser != null) {
        helpBrowser.saveState(outState);
    }
}

@jim-daf jim-daf marked this pull request as ready for review April 25, 2026 20:47
Copilot AI review requested due to automatic review settings April 25, 2026 20:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 WebView state from savedInstanceState.
  • Persist WebView state via onSaveInstanceState() and stop clearing history/reloading in onResume().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to +101
if (savedInstanceState != null) {
helpBrowser.restoreState(savedInstanceState);
} else {
Intent intent = this.getIntent();
startPage = assetPrefix + intent.getStringExtra("page");
helpBrowser.loadUrl(startPage);
}
Copy link

Copilot AI Apr 25, 2026

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 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.

Copilot uses AI. Check for mistakes.
Comment on lines +98 to +100
Intent intent = this.getIntent();
startPage = assetPrefix + intent.getStringExtra("page");
helpBrowser.loadUrl(startPage);
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebView disappear after pressing home button

2 participants