Make WebView display another URL without leaving the previous one loaded

-1

I would like to know if in android there is any way to load in the WebView a different URL to the current one and that when going back, it would not go back to the first one, since I figure it will consume resources, and my website needs a lot to charge. I am using the .loadUrl(url); method and I have tried to use .destroy(); anter, re-identify the WebView with findViewbyId and then load the URL but the page is blank. I've also tried it with .clearHistory(); but it has not worked.

In other questions similar to this I have seen that they use .loadUrl("about:blank"); but I do not want only that the previous website is not visible, but that there are no more websites besides the new one.

Is there any other way to change the current URL to a new one without the previous one remaining?

    
asked by pepito 27.07.2017 в 07:22
source

1 answer

1

You can do the following to delete the history each time you upload a new page.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    webView = (WebView) findViewById(R.id.webView);

    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

            view.clearHistory();
    });
}

But anyway, pressing the back button does not go back in the webview's history, unless you overwrite any of the methods onKeyDown() or onBackPressed() .

The previous page also does not stay loaded, but what you do when you navigate backwards in the history is to reload it.

    
answered by 27.07.2017 в 14:32