I have a question on the Android webview.
Assume URL A redirects to URL B.
My android application when it tries to open URL A, webview automatically redirects to URL B.
If a URL is being redirected to some other url, I see both these urls are stored in webview history. Now my webview history consists of [, , URL A, URL B ]
On back key click from URL B webpage, webview will try to load URL A, which again redirects to URL B. We need to double click back key to go back beyond URL A
How do I solve this issue ? Struggling from the past 2 hours :(
If overriding
shouldOverrideUrlLoading()
, then return false. May not be correct way but it works for me.i have the problem too, now already solved the problem.
solution
**If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url. **
Try to overload the OnBackPressed() to overide the default hard key back action. there u can finish the current activity or control how you want.
I have a same problem too, and figured out how to solve it. It's like yours. When I click the first link(www.new.a) it automatically redirects other link(mobile.new.a). Usually the links redirect two or three, and my solution have been worked on almost every redirect links. I hope this answer help you out with annyoing redirecting links.
I finally figured out that. You need a WebViewClient with four APIs. There are shouldOverrideUrlLoading(), onPageStarted(), onPageFinished(), and doUpdateVisitedHistory() in the WebViewClient. All the APIs you need is API 1 so don't worry about.
It goes like this. You can use other function rather than onKeyUp().