我在我的應用程序中有一個webview,首先它加載a.html,單擊a.html中的一個按鈕,然後b.html將被加載,單擊b.html中的一個按鈕,然後一個活動將開始。總之,訂單是a.html-> b.html->開始活動。我的webView已經擴展了WebViewClient,並覆蓋了它的方法如下。何時調用WebViewClient的方法?
private class WebViewHandler extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
Log.d("onPageStarted", "onPageStarted:" + url);
mProgress.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url)
{
Log.d("onPageFinished", "onPageFinished:" + url);
mProgress.setVisibility(View.GONE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.d("url", "onPageoverloaded the url: "+url);
String tutorialId = url.substring(url.lastIndexOf("=") + 1);
MetaioDebug.log("Tutorial Id detected: "+tutorialId);
if (url.startsWith("metaio://"))
{
if (tutorialId != null)
{
MetaioDebug.log("Native code tutorial to be loaded #"+tutorialId);
if (tutorialId.equals("1"))
{
Intent intent = new Intent(getApplicationContext(), Tutorial1.class);
startActivity(intent);
}
return true;
}
}
問題是,當a.html開始加載,但是當b.html開始加載不會被調用onPageStarted()
只調用。 shouldOverrideUrlLoading(WebView view, String url)
僅在單擊b.html中的按鈕但不在a.html中時纔會調用。
我很困惑什麼時候應該調用這3種方法?
對於最後一個問題:是的,在加載b.html之後調用onPageFinished(),但在啓動加載b.html時不調用onPageStarted()。順序應該是onPageStarted() - > onPageFinished(),但這不是在這裏發生的事情。 – Blake
'onPageFinished()'與'onPageStarted()'沒有相同的註釋,它只被調用一次。對我來說,這表明它會在每次(重新)加載資源時被調用。不幸的是,我認爲你正在看到預期的行爲。順便說一句,你是如何加載'b.html'?和「a.html」一樣嗎? – Jon
你的意思是「onPageFinished()與onPageStarted()沒有相同的註釋」?在a.html中有這樣一行''何時加載b.html – Blake