Android: WebView's method goBack() shows a blank page

Bun*_*dee 11 android android-webview

I have an android application that loads web pages in an activity with a WebView. I am using the retrieving the page manually and using WebView's loadDataWithBaseURL to display it on screen. Everything there is fine.

Now, i am trying to override the Back button press to simulate going back in the WebView history stack. I am able to override the Back button press, i can see that there is a history stack in the WebView, i can see that the history url is correct, but when i call WebView's goBack() method, it displays a blank page.

Anyone encountered this before or give me a couple of suggestions to proceed from this?

编辑:如果我使用WebView的loadUrl方法,带有覆盖的后退按钮按预期工作.但是为什么....如果我需要手动处理这个,我该如何开始搞乱历史页面?

小智 6

我也遇到了同样的问题.如果我在调用loadDataWithBaseURL时设置了historyUrl参数,我发现问题就消失了.

  • 我们应该在historyUrl中设置什么值 (2认同)

Arm*_*man 1

在调用 goBack() 之前,您应该检查 canGoBack() 方法是否返回 true