I have a WebView that is loading social media pages. I have overridden the Back button to call the
goBack method on the WebView until
false. Then it calls
true unless you tap the back button 4 times really quickly.
I’ve tried checking the original url with the current url, but the page has a different url than the one that gets passed in.
Does anyone know a way to have the back button call the WebView’s
goBack method until you are at the beginning, then call
Well, it’s not ideal but you may track the navigation history manually by using an array (or just an integer to be increased and decreased) and push the current url into it every time it changes and pop the last url from it when you press the back button, and if the array is empty (or the integer is 0) you call
To execute code when the url changes, you can override the method
boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request) of the
WebViewClient (link to the documentation).