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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With