Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

Edit: If i use WebView's loadUrl method, the Back button with an override works as intended. But why.... If i need to handle this manually, how do i start messing with history pages?

like image 787
Bundeeteddee Avatar asked Aug 26 '10 11:08

Bundeeteddee


2 Answers

I got the same problem also. I found that the problem went away if I set the historyUrl parameter on the call to loadDataWithBaseURL.

like image 142
myo Avatar answered Oct 12 '22 11:10

myo


You should check if the canGoBack() method returns true before calling goBack()

like image 26
Arman Avatar answered Oct 12 '22 10:10

Arman