androidandroid-webviewandroid-websettings

webview.goBack() is works only one time in android WebView


hi developers i am working in a webview in android. i loaded a webpage in WebView. then i click some link that contains in the webpage. Then i click the goback button in my application the onclick of the button contains the below code

webview.canGoBack();
 backbutton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                      webview.goBack();
                    }
                 });

but this code works only once. it goes only one clicked link back. i want to goback the every clicked url one by one


Solution

  • Please try it.

    backbutton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (webView.canGoBack()) {
                webView.goBack();
            }
        }
    });