Clearing Webview window

Andras

Active Member
Licensed User
Longtime User
Is there a simple way of clearing a webview window while a new page is loading - and perhaps displaying a progress bar or similar in the meantime?

And perhaps putting up a suitable message if the site fails to load...?

Thanks!

John
 

lagore

Active Member
Licensed User
Longtime User
Hi
You could use
B4X:
WebView1.LoadHtml("<html><body>Loading Page</body></html>")
and create a clear panel with an indeterminate progress bar overlayed on top of the webview then remove it when the 'PageFinished' event has fired.
 
Upvote 0

Andras

Active Member
Licensed User
Longtime User
Interesting and I'd been thinking along similar lines, but it doesn't seem to work; the original page stays visible until the new one loads.

And a question about the PageFinished event - it requires a string parameter, but what? Not the URL as I had assumed, as this throws up a Java error.

Sorry for the confusion!

John
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
The string parameter is the Url of the page just loaded it is handed to the sub "PageFinished" by the system not something you set. The only way to get the 'clear Screen' to show with message between is to not load the second web until the 'clear screen' has finished loading.
B4X:
Sub WebView1_PageFinished (Url As String)
   If Url = "file:///" Then 
       WebView1.LoadUrl("http://maps.google.com/")
   End If
End Sub
The returned Url of
B4X:
WebView1.LoadHtml("<html><body>Loading Page</body></html>")
is "file:///" so it wipes the first webview then displays "Loading Page" and then loads the next page. This can happen fairly quickly depending on connection and page size.
 
Upvote 0

Andras

Active Member
Licensed User
Longtime User
Yes, thanks, I've just spent half an hour playing with it and came to that conclusion! It's actually probably easier to just display the new panel on top of the webview until the PageFinished event has done its job; this seems seems quite happy to work with WebView1_PageFinished ("dummy").

The indeterminate bar is fine as far as it goes, but I'd been expecting the 'barbers pole' animation rather than this; or is that a 'feature' of some devices? If not, is it available here - doesn't seem to show up in any of the libraries?

Thanks again,

John
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
As standard there only 2 versions of progress in B4A, the spinning wheel (indeterminate) and horizontal which it is up to you to increment. Android does have a horizontal indeterminate version ' Widget.ProgressBar.Horizontal' you should be able to use the Reflector library to implement this (if only I knew how?)
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
As standard there only 2 versions of progress in B4A, the spinning wheel (indeterminate) and horizontal which it is up to you to increment. Android does have a horizontal indeterminate version ' Widget.ProgressBar.Horizontal' you should be able to use the Reflector library to implement this (if only I knew how?)

Try this untested code:
B4X:
Sub setIndeterminate(pb as ProgressBar)
Dim r As Reflector 
r.Target = pb
r.RunMethod2("setIndeterminate",true, "java.lang.boolean")
End Sub
 
Upvote 0

Andras

Active Member
Licensed User
Longtime User
Try this untested code:
B4X:
Sub setIndeterminate(pb as ProgressBar)
Dim r As Reflector 
r.Target = pb
r.RunMethod2("setIndeterminate",true, "java.lang.boolean")
End Sub

Interesting, but promptly throws up a 'Missing Library?' error for Reflector.

John
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
hi

I have the same Problem
I load images into a webview.
Now when i used this function and close my app and open it again it crashes
its because of the webview

I tried
Sub ClearWV
WebViewtown1.LoadUrl("")
WebViewtown1.Invalidate
DoEvents
End Sub

but it didn´t help

I have a galaxy s2 with android 4.0.3

Hope you can help me out
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Hi Erel

Sorry for dont answering this

i think its this line in the logs -->

Fatal signal 11 (SIGSEGV) at 0x546406e4 (code=2)

Every time i use a funktion with webview(loading a bitmap)
and i close my app, this error is in the log

If i use recycle to recycle the webview it logs this -->

java.lang.NoSuchMethodException: recycle [boolean]
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getDeclaredMethod(Class.java:685)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:192)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:795)
at webview.android.main._activity_pause(main.java:233)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at webview.android.main.onPause(main.java:159)
at android.app.Activity.performPause(Activity.java:4563)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1198)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2705)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2674)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2652)
at android.app.ActivityThread.access$800(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1170)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NoSuchMethodException: recycle [boolean]
 
Last edited:
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Hi erel

This is my code -->
B4X:
dim o4 As Reflector
o4.Target = webview1
o4.RunMethod2("recycle","True","java.lang.boolean" )

When i use Exitapplication (userclosed=true) after loading a bitmap into a webview (picture comes from a website via loadurl) then the log gives this error -->
Fatal signal 11 (SIGSEGV) at 0x53a576e4 (code=1) what does this mean?
if i use webview to load bitmaps into it and in activity_pause exitapplication it chrashes everytime on second start.

I have a galaxy s2 with android 4.0.3 (i think the problem is only in ics)
Sample Projekt webviewissue --> http://www.b4x.com/forum/german-forum/19150-ram-problem.html

Hope you can help me :), because this error is very annoying
 
Last edited:
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Where did you see a reference to this recycle method?

Why are you calling ExitApplication? It should normally not be used.

What do you mean by where did you see a reference?
I downloaded the reflection library and set this code into activity_pause

I need exit application because, if i dont use exitapplication the ram is increasing everytime i start my app again.
With Exitapplication the ram is not increasing.

How can i handle this problem that my ram is getting fuller and fuller with every new start of my application?
I use a lot of bitmaps (with loadbitmapsample) some bitmaps are loading in webviews.

Is this my recycle code wrong?
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
It could be that the WebView is using a lot of memory to hold items in it's cache.

Try using my WebViewExtras library to clear the cache:

B4X:
MyWebViewExtras.clearCache(MyWebView, ??)

Experiment with values of True and False for ?? includeDiskFiles:

IncludeDiskFiles - If false, only the RAM cache is cleared.

There's no point clearing disk files unless you really want to - clearing disk files will negate the speed gain of having cached files.

Martin.
 
Upvote 0
Top