查找排球请求响应时间android [英] finding volley requests response time android

查看:84
本文介绍了查找排球请求响应时间android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用凌空抽空打给服务器.我正在尝试将每个请求的响应时间发送给Google Analytic(分析),以分析服务器延迟,在凌空jsonobject请求中,有什么方法可以找到每个请求的响应时间. 如果volley不提供此功能,如何计算每个请求的响应时间?

I have been using volley for making rest calls to server. I am trying to send the response time for each requests to Google analytic to analyze the server latency, in volley jsonobject request is there any way to finding the response time for each requests. If volley doesn't provide this function how can I calculate the response time for each requests?.

推荐答案

您需要自己计算.这是查看响应需要多长时间的一种快速方法:

You'll need to calculate this yourself. Here's a quick way to see how long it takes for the response to arrive:

private long mRequestStartTime;

public void performRequest()
{
    mRequestStartTime = System.currentTimeMillis(); // set the request start time just before you send the request.

    JsonObjectRequest request = new JsonObjectRequest(URL, PARAMS, 
        new Response.Listener<JSONObject>() 
        {
            @Override
            public void onResponse(JSONObject response) 
            {
                // calculate the duration in milliseconds
                long totalRequestTime = System.currentTimeMillis() - mRequestStartTime;
            }
        },
        new Response.ErrorListener() 
        {
            @Override
            public void onErrorResponse(VolleyError error) 
            {
                long totalRequestTime = System.currentTimeMillis() - mRequestStartTime;
            }
        });

    requestQueue.add(request);
}

这篇关于查找排球请求响应时间android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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