您可以测量在Android的webView中加载网页所需的时间吗? [英] Can you measure the time it takes to load a web page in a webView in Android?

查看:289
本文介绍了您可以测量在Android的webView中加载网页所需的时间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于Android中的WebView加载时间太长,有很多问题,但是我希望能够准确计时完全加载并显示结果所需的时间.

There are lots of questions regarding the WebView in Android taking too long to load, however I'd like to be able to time exactly how long it takes to completely load, and then display the result.

这可能吗?我可以启动一个计时器,但是WebView加载后是否具有HTML OnLoad样式调用?

Is this possible? I could start a timer but does the WebView have an HTML OnLoad style call once it has loaded?

我拥有的代码是基本的:

The code I have is basic:

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.pageloadtest);

        webView = (WebView) findViewById(R.id.webView1);
        webView.loadUrl("http://www.airometricwireless.com");
}

这样可以很好地加载页面.我只需要时间需要多长时间.

This loads the page fine. I just need to time how long it takes.

推荐答案

可能在科学上不够准确,但我想您可以致电

Probably not scientifically accurately, but I guess you could call

long a, b;

mWebView.setWebViewClient(new WebViewClient() {

    public void onPageStarted(WebView view, String url) {
        a = (new Date()).getTime;
    }

    public void onPageFinished(WebView view, String url) {
        b = (new Date()).getTime;
    }
});

然后b-a.

希望有帮助.

最诚挚的问候.

这篇关于您可以测量在Android的webView中加载网页所需的时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆