Marvin Emil Brach
Marvin Emil Brach

Reputation: 3972

WebView in Android emulator loads page but doesn't display the content

While testing appcache issues for an offline WebApp I stumbled over a problem with the emulator: I tried to load a webpage in the WebView. Sometimes it shows perfectly, sometimes it shows nothing. First I thought it was my fault - overseeing some buggy code i inserted while testing. But that's not the case.
Instead I believe it's a bug (or a misconfiguration) of the emulator itself. Because if I call

    myWebView.loadData("<html><body><h1>TEST</h1></body></html>", "text/html", "UTF-8");

and then

    myWebView.loadUrl("http://10.0.2.2:8080/FrontEnd/index.jsp");

the view shows an heading "TEST", instead the content of the index.jsp. So I added to the index:

    $(alert("Hallo Welt!"));

And now, it shows my expected toast "Hallo Welt!" -> Page was received and somehow processed.
BUT: the display shows not my index.jsp - instead the TEST resides.

Additionally i observed that app-symbols in "All Apps Menu" got cut in half and the lowest row wasn't shown, too. Perhaps it's a incompatibility with graphics driver or similarly!?

Is anybody aware of that problem or can give me a hint how to fix that?

Upvotes: 1

Views: 1438

Answers (1)

Marvin Emil Brach
Marvin Emil Brach

Reputation: 3972

And the problem was: reacting on JS-alerts with an Toast:

    myWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            Logger.getLogger("js-console").log(Level.INFO, "received js-alert!");
            Toast toast = Toast.makeText(view.getContext(), message, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return true;
        }
    });

but NOT calling

    JsResult.confirm();

After adding this line after toast.show(); and before return true; all works like expected... ... ... ...

Upvotes: 1

Related Questions