Webview not working as expected

mistermentality

Active Member
Licensed User
Longtime User
I have a webview on a tabbed screen load in an internet page but regardless of whether I have zoom enabled in the designer or not I get no option to zoom in or out to see the whole web page and have no idea why as I have used same webview command in my gps app with no such problem on the same phone.

The code is:
B4X:
searchurl = "http://www.cosmeticsdatabase.com/wordsearch.php?query=" & ingredient
WebView1_netsearch.LoadUrl(searchurl)

The only differences between this and the gps apps webview call is the gps app called a google map and was not on a tabbed screen. Here the webview is the only item on the tabbed screen.

One other webview issue is that on an emulator the app loads the default page of "file:///android_asset/default.html" properly but on the phone it shows just a white area with nothing inside it for some reason. That uses the command:

WebView1_netsearch.LoadUrl("file:///android_asset/default.html")

Any ideas greatfully appreciated, thanks

Dave
 

mistermentality

Active Member
Licensed User
Longtime User
Embarrasingly I have figured out one webview error, the zoom part, which turned out to be my fault as using the webview on a tabbed screen I forgot to adjust the webview height and when I adjusted it the zoom buttons were visible.

But the default html page only ever displays once and after that shows as a white blank page unless the apk is reinstalled, it appears to be a bug but I will explain in more detail in case it is not.

The page I load into the webview is called default.html and is included with the apk when it is installed (as an asset). If I put the apk on my phone then the first time I run the app after installing it the default page is shown fine in the webview.

However if the app is in the background and I bring it to the front again to use it then the page has vanished and been replaced with a white area, the same thing happens if I quit the app and run the app again later.

In other words the code
B4X:
WebView1_netsearch.LoadUrl("file:///android_asset/default.html")
Only displays the page once, and that is on the first run after installation. Any time after this and it is just a blank white page. The html page is a very very basic page with just a few lines of text and a link to google as shown here....
B4X:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="PageCreate">
<title>Is it safe?</title>
</head>
<body bgcolor="#99CCFF" background=""><font face="Arial" size="2">If you ask me to search the internet for any ingredient I cannot find listed as harmful in my database the resulting web page will be shown here.<br>
If you would like to browse the internet for any reason in the mean time you can do so without the need to open a web browser by clicking &nbsp;
<a href="http://m.google.com">here</a>.</font></body></html>

The same thing happens if I just have a tabbed screen with a webview call this page so it doesn't appear app related, and I have no other code that calls internet pages or makes internet calls in the app so cannot understand why it is doing this.

I have found it will display the page fine if I use the home button to dismiss the app from the screen, but not if I use the back button. This also happens using the app.

However even then the white screen is still displayed next time the app is run.

Any ideas anyone. Please?

Dave
 
Last edited:
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
I've found a temporary solution by reloading the page whenever the app is resumed, this somehow also stops the white page appearing when restarted but to do this I have to keep track of the current url but it is working.

I do not know why, without this, in my four tabbed screen a white screen shows but at least I have a work around now.

I tried a very simple app with two tabs and a webview and it didn't show a white screen, and I checked my code and it had no other webview calls, so maybe it is because I have four tabs but I have a workaround for now. Thank you for the quick reply and if I find out why it shows the white page I will post the answer here.

Dave
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
I think that you have probably not understood the Activity lifecycle. When put into the background the Activity may be destroyed so you have to save your Activity state in Activity_Pause and restore it in Activity_Resume. Read Erel's tutorial on it http://www.b4x.com/forum/basic4andr...87-android-process-activities-life-cycle.html


It's possible but in tests I have even just pressed back button on phone then within seconds used app again and it does the same thing. After reading your reply I checked and noticed also check boxes are also reset when resuming so your reply looks like the answer but if so it is odd I never had this problem with my gps app. However it seems to be the answer, and makes sense.

Thank you :)

Dave
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
BTW, what Android version tested with WebView ? Emulator ?
I had a problem with WebView navigating (after the initial opening) in v.2.1 of 400 pixels height resolution. When created 320x480 v.2.1 - no problem with WebView now.

EDIT: really, Emulator v.2.1 with screen WVGA400 works strange, makes error about initialization and so on, and WebView works wrong.
The same emulattor with HVGA is fully OK.
But layouts are prepared for HVGA, sure.
 
Last edited:
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
BTW, what Android version tested with WebView ? Emulator ?
I had a problem with WebView navigating (after the initial opening) in v.2.1 of 400 pixels height resolution. When created 320x480 v.2.1 - no problem with WebView now.

EDIT: really, Emulator v.2.1 with screen WVGA400 works strange, makes error about initialization and so on, and WebView works wrong.
The same emulattor with HVGA is fully OK.
But layouts are prepared for HVGA, sure.

Tested on Android version 2.2 on real device and emulated device (both 320x480 resolution), both show same problem but I now work around it by storing the current values in a map and then when the app is paused or resumed saving or reading those values to or from the map.

Emulator works fine for me except if I try a 1024 screen resolution as I am unsure of the correct density needed for that.

Dave
 
Upvote 0
Top