gpt4 book ai didi

android - 首次调用 WebViewClient 时页面加载缓慢

转载 作者:行者123 更新时间:2023-11-29 22:06:55 24 4
gpt4 key购买 nike

下面是我的 WebViewClient 代码。我通过单击按钮调用了该类。

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.webview);

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);

if (progress == 100)
activity.setTitle(R.string.app_name);
}
});

webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// Handle the error
}

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

webView.loadUrl("http://mylink.com");
// String customHtml =
// "<html><body><h1>Hello, WebView</h1></body></html>";
// webView.loadData(customHtml, "text/html", "UTF-8");

}

}

Error Image

加载 WebViewClient 需要更多时间。我需要加快速度。有什么建议

最佳答案

据我所知,您的代码没有任何问题。我强烈建议您检查您所连接的 Web 服务器的性能,因为这很可能是您出现问题的原因。特别是查看服务器响应时间。要测试 Web View 的性能,请尝试将 URL 设置为快速响应的网站,例如 google.com。

关于android - 首次调用 WebViewClient 时页面加载缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10579176/

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