当onReceivedTitle
网址更改时,下面的方法webview
每秒调用2-3次。我想在上次调用onReceivedTitle
时在其中调用方法。我这样做是因为我只想在Webview中监视url的更改。当URL通过Ajax更改时,不会调用shouldOverrideUrlLoading
。
class MyWebChromeClient extends WebChromeClient {
@Override
public void onReceivedTitle(WebView view, String title) {
Log.v("onReceivedTitle", "=>" + title);
// callAMehod();
super.onReceivedTitle(view, title);
}
}
最佳答案
您可能要使用Handler并执行以下操作:
class MyWebChromeClient extends WebChromeClient {
private boolean mOnReceivedTitleInvoked;
@Override
public synchronized void onReceivedTitle(final WebView view, final String title) {
if (!mOnReceivedTitleInvoked) {
mOnReceivedTitleInvoked = true;
Log.v("onReceivedTitle", "=>" + title);
handler.postDelayed(new Runnable() {
@Override
public void run() {
super.onReceivedTitle(view, title);
mOnReceivedTitleInvoked = false;
}
}, 1000);
}
}
}
尽管您可能想重新考虑
onReceivedTitle
行为。