Android Question Destroy WebView & WebViewExtras

Hi Dears
I have a problem in reuse WebView & WebViewExtras
Dim WebVE As WebViewExtras
Dim webv As WebView
Dim WebViewClient1 As WebkitWebViewClient


WebVE.JavaScriptEnabled = True
WebVE.addJavascriptInterface(ji, "B4A")
I want to delete the cache after logging in and log in again with new session, but As long as the app is not closed and restarted, it is not possible to log in to the site again and the page will be loaded with the same previous session.
    WebVE.JavaScriptEnabled = False
    webv.JavaScriptEnabled = False
I would be grateful if you could advise how I can make the browser reusable
The site I work with does not have cookies at all.
The story goes like this:
I login with my first account, then save the cached data to the zip file The second time I try to login with the second account, even after deleting all the cache files, the browser still uses the data of the first account.
But when I close and open the program and extract the zip file before LoadUrl and entering the site, the possibility of logging in with the second account is provided.
The question is why there is no way to reset the browser like when we run the app
Upvote 0


Well-Known Member
Licensed User
Longtime User
i imagine what you have described is all clear in your head, but - reading it - it isn't very clear in mine. i have some questions/comments:

setAppCacheEnabled() is, essentially, a noop. why you would want it in any case is not clear, since you seem not to want caching. why are you enabling it?
setCacheMode( ... LOAD_DEFAULT) = use cache, which is - apparently - what you do not want. i would think you would want LOAD_NO_CACHE
setDOMStorageEnabled(true) = turn on DOM storage. if you turn it on, you might just get some. which you maybe do not want... i don't know what the
web page you access does, but if DOM storage is used, then previously stored data could easily reappear even though cache has been cleared.

i'm guessing you run the second set of websettings after exiting the first login. you'd think you'd want to run all those settings before loading a url, not after... what, exactly, do you mean by "same previous session"? what do these sessions look like?

in addition to all those settings you try to control, you may need to take into account the webview.db and webviewCache.db, which are separate caching entities that might need to be cleared. preferably, deleted. if you've looked at where webview stores cached data, you would have seen the databases in addition to the cached pages and images.

there is also the matter of cookies. you say you don't have any, but things like session id's are usually sent via a cookie.

you might also need to be aware of this:
"The username and password used for http authentication might be cached in the network stack itself.
WebView does not provide a special mechanism to clear HTTP authentication for implementing client logout.
The client logout mechanism should be implemented by the Web site designer (such as server sending a
HTTP 401 for invalidating credentials)."* in other words, clearing the webview cache may have nothing to do with
logging in and "logging out" (which apparently has no meaning for webview in any case).

how, exactly, are you saving cached data? i won't ask why you're doing this, but i will ask what does it mean to "save the cached data"? and what does it mean to "extract" the cached data before loading url"? what does that extraction do? and what does it have to do with anything? i don't follow why you even mention it. why do you?

and, last, the system makes decisions regarding what it wants to cache based on request and response headers. unless you are aware of the contents of all those headers for the requests and responses that make up a "session", you may have little control over the inner workings of webview. pages and images (ie, data) are only a part of requests and responses. as an example, headers can contain caching instructions.
Upvote 0
For example, suppose we are working with Telegram Web The session required to connect to the server is generated by JavaScript. So there are no cookies. I need to save several accounts so that every time I want to log in with one of them and save all the cached data, I can restore it again for logging in with a new account. But this does not happen unless I close the program once and open it again. Otherwise, even though I delete all the cached files, the current session still exists


I save the contents of these directories to have my account session for later use and delete these directories before restoring. And even though I delete and restore, the same session as before is still going on. Although I reset all the settings
Last edited:
Upvote 0


Well-Known Member
Licensed User
Longtime User
in theory, what you have done "works". that is to say, it clears or
deletes everything you know about and ask it to clear or delete.
and there are no logged errors. i tested, myself. as a plan, however,
what you have done obviously doesn't work.

i still think you don't take into account exactly how webview works (if you did,
you would have moved on to a different plan by now). it's also not clear
that you understand how the other side works. you hint that it's
telegram web, but you don't actually say. it's also not clear exactly what
your app does. again, if you fully understood how telegram (or whoever
it is) works, you would have moved on to a different plan.

under normal circumstances, if some obvious mistake jumps out,
forum members can usually make valuable suggestions. valuable
or not, i've commented on some of your tactics that struck me as
dubious. i'm guessing you disagree, as you simply ignored them.
no harm, no foul. although i thought webview's inability to log you out
might concern you. whatever.

my only other suggestions would be:
write a small 2nd app (not an activity that is part of your main app) that
logs in to your account while app 1 is still logged in (and now in background).

1) run app 1 and log in to the service
2) when that is successful, tap a button to clear/delete the cache, etc.
3) tap home button to get launch screen
4) launch app 2 and log in to the service.

can you log in on app 2? or does the session from app 1 appear?

also see if you can find an appropriate place for webview.loadurl("about:blank") somewhere.

by the way, if the service is telegram, telegram says it does use cookies...
Upvote 0