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
 

mcmanu

Active Member
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:



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.

Okay thank you very much i will give it a try :)
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
WebView doesn't have a recycle method. So you are getting an error when you try to call it with Reflector.

Oh right thank you :)
In my other thread i posted bevor, there i a link to a forum, he uses Webview.clearDrawablecache and webview.clearcache
is Webview.clearDrawablecache in the Library from warhound?

Well I will test it, thank you very very much i hope it will solve the Problem :)
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Hi Erel

Can i only recycle bitmaps?
or is it possible to recycle bitmaps on a button,imageview,listview?

For examle

dim infoflag as imageview
infoflag.Initialize("infoflag")
Activity.AddView(infoflag,10dip,430dip,60dip,60dip)

and then in activity_pause

dim recycleit as reflector
recycleit .Target = infoflag
recycleit.RunMethod2("recycle","true","java.lang.Boolean")
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Did you try the WebViewExtras clearCache method?

It 'should' do exactly what you want - clear the WebView's cached memory usage.

Martin.
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Bitmaps do have a recycle method.

So i cannot recycle a imageview or button which contains a bitmap?

Because in all my imageviews or buttons i set the background with this method
-->
backbutton.setbackgroundimage(loadbitmapsample(file.dirassets,"test.png",activity.with,activity.height))


do i have to write it like this so that recycle works? or is my code with setbackgroundimage okay for recycling the bitmaps? -->

dim bitmap1 as bitmap
Dim Bitmap1 As Bitmap
Bitmap1.Initialize(File.DirAssets, "X.jpg")
button1.setbackgroundimage(bitmap1)
 
Last edited:
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Did you try the WebViewExtras clearCache method?

It 'should' do exactly what you want - clear the WebView's cached memory usage.

Martin.

No sorry not yet because yesterday i tried to freeing bitmaps :)
but i will give it a try today and let you know :)
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
I have written this little example, where you can see my biggest problem
i need exitapplication to free the ram (because nothing really nothing helps,invalidate nope ect nope) so i hope there is an another option :)
Or i make something wrong!?

I used your webviewextras it works, but i think the issue is an another problem and its possible not related to the cache

Example -->
Webviewissue.zip download - 2shared

Sorry to use an uploader but the file is bigger than the allowed size ;)


EDIT: I found out that the problem with webview and exitapplication is related by Ice crem sandwich (or i think so) because on my galaxy ace ist works perfektly, with my samsung galaxy s2 with android 4.0.3 it chrashes.
Has anybody here a Galaxy s2 without ics and can test it for me?
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
EDIT: I found out that the problem with webview and exitapplication is related by Ice crem sandwich (or i think so) because on my galaxy ace ist works perfektly, with my samsung galaxy s2 with android 4.0.3 it chrashes.
Has anybody here a Galaxy s2 without ics and can test it for me?

Must be a Galaxy S2 issue then as your app works fine on my ICS Elf2 tablet.

Martin.
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Hi

oh right Thank you very much for testing it :)
Maybe i test it with other android phones too :)
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Galaxy s2

Hi,
is it possible to get the device name which is using my app?
i need all galaxys2 models

and a question to cache
if i use webextras to free the cache, is it this cache showed in the picture i attached? because everytime i load a picture into webview this cache gets 500 kb

And here is an error i get i think this is the hole problem -->

java.lang.IllegalStateException: Tried to setNewPicture with a delay picture already set! (memory leak)
at android.webkit.WebView.setNewPicture(WebView.java:11038)
at android.webkit.WebView$PrivateHandler.handleMessage(WebView.java:10628)
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)

and this annoying thing -.- --> Fatal signal 11 (SIGSEGV) at 0x53d426e4 (code=1)


Thanks in advance :)
 

Attachments

  • Screenshot_2012-07-06-17-18-12.png
    Screenshot_2012-07-06-17-18-12.png
    75 KB · Views: 204
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

You can use the Phone library to get the device Manufacturer, Model and Product.

The clearCache method, if passed True (so that disk files as well as memory files are cleared), will i think clear the databases that exist on the device's internal memory at:

/data/data/your.package.name/databases/webview.db
/data/data/your.package.name/databases/webviewCache.db

If you have a rooted device and look at the size of those .db files before and after calling the clearCache method you'll see them cleared.
I think if you pass False to clearCache then those databases will not be changed as only files cached in memory would be cleared.

Now if you can run your app again and use the WebView so that it's cache is populated and then use the Settings Clear Cache button as in your screen grab then you can see whether that button does the same as the clearCache method.

I've searched a bit for more info on the IllegalStateException but found nothing.
The only search results link back to the WebView source code- no reports from other developers experiencing that problem.
So i'm not sure what to suggest there.

If it relates to a bug in Galaxy firmware then you might have to search in more details - look for forums where Galaxy developers might post such problems.

Martin.
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
hi

Wow thank you very much for the information :)
I found something that overcome this Problem.
In the settings of my galaxy s2 there is a setting to limit the Processes
i turned it to maximal 3 processes for apps, after that
webview works perfectly after restarting my application :)
aw man i worked for 2 weeks to try solving this Problem and now its only a setting change xD
Thank you very much erel and warwound for your pleasant help :)
and sorry for being so annoying :p xD
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Webview issue text

Here is the Manual
---> hope it helps

Edit: unfortunately if you restart your mobile you have to set the setting again --> shame on you samsung xD
 

Attachments

  • Webviewintroduction.zip
    223.7 KB · Views: 242
Last edited:
Upvote 0
Top