I have a WebView
in my application that displays HTML data downloaded from a webpage. Why do I load the HTML rather than the URL alone? Well, in order for me to allow offline search, I download the HTML data and store it on an SQL database.
Everything works well, and subsequent calls to loadDataWithBaseUrl()
work well, and keep on loading correctly on my WebView
, but whenever the user presses the back key, the user is just taken back to the last activity on the stack, rather than going back.
I tried using the following code:
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
But then I tried forcing the WebView
to go back, without checking if it could or not, via:
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
myWebView.goBack();
return true;
}
but nothing happens, it just stays on the same place.
As an FYI, I've tried passing null
and an actual URL when calling loadData()
, here's how I have it set right now:
view.loadDataWithBaseURL(mUrl, mHtmlData, SearchUtils.MIME_TYPE, SearchUtils.CHARSET, "");
I read this answer but I am hoping for better luck.