开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜