I have an activity that does OAuth authentication by intercepting the redirect url once it show up in the webview. However, the onPageFinished function is somehow called twi
If the url is OK after onPageStarted method starts onPageFinished, but if the url is redirected after onPageStarted starts shouldOverrideUrlLoading and then onPageFinished. You should just check if the loading URL is redirected or not
private boolean isRedirected;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if (!isRedirected) {
//Do something you want when starts loading
}
isRedirected = false;
}
If the URL is redirected the callback starts this function
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
isRedirected = true;
return true;
}
Before doing something in onPageFinished check if the callback has entered into shouldOverrideUrlLoading method
@Override
public void onPageFinished(WebView view, String url) {
if (!isRedirected) {
//Do something you want when finished loading
}
}