我如何加载下一个web视图之前明确previous的WebView内容?视图、加载、明确、内容

由网友(心囚)分享简介:我的方案最初是我加载的WebView,后来我加载相同的WebView有不同的URL。My scenario is initially I am loading a WebView and later on I am loading the same WebView with a different URL.我的问题...

我的方案最初是我加载的WebView,后来我加载相同的WebView有不同的URL。

My scenario is initially I am loading a WebView and later on I am loading the same WebView with a different URL.

我的问题是,每当我加载下一个URL,我可以看到previously加载URL的内容,然后我当前加载URL的内容被显示出来。

My problem is whenever I am loading the next URL I can see the previously loaded URL contents and then my currently loaded URL contents gets displayed.

我想清楚了,每当我加载了不同的URL的内容。

I want to clear the contents whenever I am loading the different URL.

说,

if (pos == 0) {
    mweb.clearCache(true);
    mweb.clearHistory();
    mweb.loadUrl("http://stackoverflow.com/");
}
else if (pos == 1) {
    mweb.clearCache(true);
    mweb.clearHistory();
    mweb.loadUrl("http://android.stackexchange.com/");
}

两个 clearCache() clearHistory()对我来说是行不通的。

Both clearCache() and clearHistory() does not work for me.

推荐答案

使用 mweb.clearView(); 之前加载新的URL

use mweb.clearView(); before loading the new URL.

编辑:

ClearView的()是pcated在API层面18. WebView.loadUrl(有关:空白)德$ P $ 可靠复位视图状态和释放网页资源(包括所有正在运行的JavaScript)。

clearView() was deprecated in API level 18. Use WebView.loadUrl("about:blank") to reliably reset the view state and release page resources (including any running JavaScript).

来解决@Liang提出的问题:

to solve the issue raised by @Liang:

要具有一致的后退导航,可以覆盖onPageFinished,和里面检查网址是否包含有关:空白与否。如果是的话,请使用webview.goBack()

To have a consistent back navigation, you can override "onPageFinished", and inside it check whether the url contains "about:blank" or not. if yes, use "webview.goBack()"

阅读全文

相关推荐

最新文章