Android Webview: Is there a way to know what the previous URL is?

Gibson picture Gibson · Oct 18, 2011 · Viewed 11.5k times · Source

Is there a way to access the history so that I know what URL the user is visiting when they hit the back button (which calls WebView.goBack())?

Answer

eldy picture eldy · Dec 4, 2013
String historyUrl="";
myWebView = (WebView) findViewById(R.id.webViewContent);
WebBackForwardList mWebBackForwardList = myWebView.copyBackForwardList();
if (mWebBackForwardList.getCurrentIndex() > 0) 
    historyUrl = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex()-1).getUrl();

// Previous url is in historyUrl