Probably it will have a simple solution but I've read many threads here but no way. In a ListView, if i tap on a row it opens a new Activity. In that activity I make an httpget and I create an html string with what I need from that httpget (a portion of the web page retrieved).
So I simply make a loadDataWithBaseURL("http://base_path.com/", html, mime, encoding, null)
.
It works as expected and I view the web page with links and images. Now the problems come... If I tap on an image I see the large image in that windows but once i press the "back" on the phone I see a white page. I know that it is caused by the "null" argument but... what I should put to see the html page again? I tried to put "html" instead of null but I see the html code inside the webview!
This is my onKeyDown
to override the back button:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the BACK key and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// If it wasn't the BACK key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
I found some information at this answer: Android: WebView's method goBack() shows a blank page
You need to provide a URL to back into when you call
loadDataWithBaseURL("http://base_path.com/", html, mime, encoding, null);
You are passing null so defaults to 'about:blank'. Try this instead:
String baseUrl = "http://base_path.com/";
loadDataWithBaseURL(baseUrl, html, mime, encoding, baseUrl + filename);
As a workaround i made the following activities.
In this way the image loads in the default Android browser and i can close it with the back button.
It is not fine to go outside the WebView but i had no other choices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With