Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore history and current page on resuming webview

I have a webview that I am navigating within. I have implemented go back and go forward. My problem is that when I return to the webview after visiting another activity, the history is lost i.e. the webview starts from the first url.

How do I code it so that after I call finish on the webview to swap to another activity on returning to the webview, the WebBackForwardList is restored and I am taken to the page I was on when I left the webview?

I have tried overriding onSaveInstanceState and onRestoreInstanceState using webview.save/restoreState(bundle) but with no success.

I have achieved returning to the last page by saving the last url in preferences, but have been unable to restore the entire history.

like image 326
qubz Avatar asked Nov 06 '22 04:11

qubz


1 Answers

Are you reusing the webview?

The javadoc for restore() says:

This method should be called to restore the state of the WebView before using the object. If it is called after the WebView has had a chance to build state (load pages, create a back/forward list, etc.) there may be undesirable side-effects.

so regenerating the webview object may help.

Other avenues to research:

  • WebView.restore() calls list.addHistoryItem(item) without clearing the list, so if you have a webView that is getting reused, it may help to call webView.clearHistory() first before the restore().

  • This SO answer implies that there is a message you can send to the history list to add items.

Good luck , and please post back your progress.

--larry

like image 74
larham1 Avatar answered Nov 14 '22 20:11

larham1