2017-07-04 78 views
0

我有一個webView,它改變了它的加載網址,點擊按鈕。 一切工作正常,除了加載的網址似乎沒有正確清除。Webview不清除上一頁Android

前一個URL中加載web視圖,並顯示出現新的URL之前。我試着用

webView.clearView()

webView.clearHistory()

webView.loadUrl( 「關於:空白」)

web視圖.clearCache(真)

和還試圖清除COO KIES。但沒有任何幫助正確清理webview。

我也試過webView.destroy();但webView被完全銷燬,因爲我無法加載下一個網址。

請幫忙。

回答

0

這份訂單爲我工作

 mWebView.clearCache(true); 
     mWebView.clearHistory(); 
     clearCookies(this); // Activity context 


@SuppressWarnings("deprecation") 
    private void clearCookies(Context context) 
    { 

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      CookieManager.getInstance().removeAllCookies(null); 
      CookieManager.getInstance().flush(); 
     } else 
     { 
      CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context); 
      cookieSyncMngr.startSync(); 
      CookieManager cookieManager=CookieManager.getInstance(); 
      cookieManager.removeAllCookie(); 
      cookieManager.removeSessionCookie(); 
      cookieSyncMngr.stopSync(); 
      cookieSyncMngr.sync(); 
     } 
    } 
+0

仍是問題仍然存在。我試圖加載一個手動輸入到編輯文本的網址。當我按下按鈕時會加載網址。但是在加載下一個url之前,第一個webview會留在視圖中一段時間​​。即使應用了您的技術,問題仍未解決。 – Jishnukanth

0

你有你的MainActivity.java這個功能呢?

private class MyBrowser extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mailto:") || url.startsWith("mms:") || url.startsWith("mmsto:") || url.startsWith("market:")) { 
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
      startActivity(intent); 
      return true; 
     } 
     else { 
      view.loadUrl(url); 
      return true; 
     } 
    } 
} 
+0

不,我正在使用一個片段 – Jishnukanth