gpt4 book ai didi

android - onPageStart 被调用多次并且 onPageFinished 没有被单页调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:03:47 26 4
gpt4 key购买 nike

我的问题不同于this一个人..我希望我的进度对话框在页面加载开始时启动,并在我的 web View 中页面加载完成时结束。我的问题是进度对话框启动并且永远不会被解雇。我设置了断点它表明进度对话框启动并多次被解雇然后它启动并且即使在页面加载完成后也不会被解雇。我的问题是为什么 onPageStarted 会为单个页面加载执行多次?为什么在页面加载完成后不调用 onPageFinished?

       myWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
myWebView.loadUrl(url);
return true;
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(myWebView, url, favicon);
Log.d("mytag","Page Loading Started");
//myURLProgressDialog= ProgressDialog.show(WebviewExampleActivity.this, "Page Loading", "Wait for a moment...");
}
@Override
public void onPageFinished(WebView view, String url) {
Log.d("mytag","Page Loading Finished!");
super.onPageFinished(myWebView, url);
//myURLProgressDialog.dismiss();
}

});

我的自标记过滤日志是这样的,用于加载单个页面:

   10-06 10:32:49.298: DEBUG/mytag(508): Page Loading Started
10-06 10:32:49.998: DEBUG/mytag(508): Page Loading Started
10-06 10:32:50.048: DEBUG/mytag(508): Page Loading Finished!
10-06 10:32:50.048: DEBUG/mytag(508): Page Loading Started
10-06 10:33:00.898: DEBUG/mytag(508): Page Loading Finished!

当我在已加载页面上单击链接时,它工作正常。这是日志:

10-06 10:59:25.098: DEBUG/mytag(543): Page Loading Started
10-06 10:59:30.889: DEBUG/mytag(543): Page Loading Finished!

最佳答案

使用.isShowing() 检查它是否已经打开。

final ProgressDialog mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Loading...");

browser.setWebViewClient(new myViewClient(){

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);

if(!mProgressDialog.isShowing())
{
mProgressDialog.show();
}

}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);

if(mProgressDialog.isShowing()){
mProgressDialog.dismiss();
}
}

});

关于android - onPageStart 被调用多次并且 onPageFinished 没有被单页调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7670364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com