Vale Vale - 4 months ago 30
Android Question

Android blank screen on onBack in a loadDataWithBaseURL

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("", 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
to override the back button:

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()) {
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);


As a workaround i made the following activities.

  1. removed the onKeyDown function
  2. removed the myWebView.setWebViewClient(new WebViewClient());

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.