weird behaviour with WebView.loadDataWithBaseURL

by Jason Proctor » Wed, 08 Jul 2009 03:53:26 GMT

Sponsored Links
 i install a WebViewClient to intercept links using 
shouldOverrideUrlLoading(). i fetch the URL content myself, 
preprocess it, then feed it to the browser using 
loadDataWithBaseURL(). as the base URL, i use the original URL of the 

this mechanism has been working reliably for a while, but recently it 
broke and i'm not sure what's going on. the symptoms i'm seeing are 
inconsistent despite the same inputs being presented. most of the 
time, the WebView displays the contents of the base URL, completely 
ignoring the "data" parameter. this is despite the preprocessing 
actually taking place and verifiably producing the correct output 
(which btw contains no links, relative or otherwise).

after reading the documentation on the loadDataWithBaseURL() method, 
which includes a note on file: URLs etc, i've been playing with the 
baseURL to see if that changes the behaviour. passing null as the 
base URL usually results in success, but of course i need relative 
links to work properly so it's not going to fly as a real solution. 
passing an http: URL initially worked, but after a few iterations 
broke, and the WebView then started just displaying the content of 
the http: baseURL.

all of this time, the failURL parameter was set to null, just so i'd 
be sure that it wasn't showing that instead.

also, Javascript and file access is enabled on the WebView via the 
WebSettings API.

IMHO, the WebView should never display the contents of the base URL. 
it's there as a string only in order to provide context for relative 
links in the data. i see notifications in my WebViewClient that it's 
calling onPageStarted() and onPageFinished() for the base URL, so 
it's doing *something* with it.

IMHO also, the WebView should call an installed WebViewClient's 
onReceivedError() method if errors happen. since 1.5 i have *never* 
seen it do this on Android (the equivalent works on iPhone, as does 
most everything else). i can see the justification for not calling it 
if there is a failURL installed, but not if there isn't.

this is crazy as i'm seeing different behaviour for the same inputs. 
literally i could see something work (like with an http: base URL) 
then rebuild it with *no* logic changes, and it would break.

any help appreciated. btw this list still does not get on with any of 
my addresses - i suspect gmail is filtering posts, now *all* posts 
not just mine, before they get to the per-user spam filter - so 
please copy directly on replies.

thanks much


Other Threads

1. Create findViewById parm dynamically or programmatically at runtime

I have an xml layout that will display a grid made up of textviews
within tablerows.  The textview names are cell00, cell01, etc.  At
runtime, my program will determine which cell needs to be changed.

Is there a way get format a name so that it can be passed to the
findViewById method at runtime?  For example, if cell00 is needed, how
can I generate the parm in this code?

TextView currcell = (TextView) findViewById(

Something like ell00 doesn compile because the findViewById
method doesn accept a String type.  I don want have every textview
name in the grid hardcoded in the program there must be a better

Thank you for any help you can provide.


2. Where is JET Creator?

Sorry for asking such a stupid question, but I just can't find the
answer. I can't even tell if this is a free download or a paid app.
describes the procedure of installing JET Creator as "simply unzip or
copy all the files in the JET Creator application directory to a
folder on your hard drive".

Well, I can't find a stand-alone download of JET Creator. I also
installed the Android SDK and AVD manager in Eclipse and then
installed everything (well, except for platform, samples and APIs that
are specific to other versions than what I want (which is 2.1), but
the elusive JET Creator is nowhere to be found. The only thing that
might be an issue is that I'm on Linux and jetcreator_manual.html only
talks about Windows and Mac. However, Linux can run Python as well, so
I thought it should be OK.


3. How can my app check if a wired headset is connected?

4. Mobile Design Conference & Workshop, BCN Design Week 21/10/2010

5. Getprop doesn't return anything

6. RobotiumForPreInstalledApps

7. Complain to the FCC about Android bloatware!