Vitto Russo Vitto Russo - 3 years ago 117
Android Question

Slow string http request with Volley

I´m currently recording lots of data from an accelerometer via blutooth from a microcontroller into an arraylist with which i processed to graph, label and trim if needed.

Later, i send this information via string http request using volley in a for loop to a url that catches this information and stores it into a PostgresQL database.

The current problem is that if i record lets say 4500 values in 3 minutes the application takes roughly 4 minutes to send all the information. Since im relativly new i don´t know if there is a better method or if there is something wrong with what i coded.

The code is as follows:

RequestQueue queue = Volley.newRequestQueue(Graphs.this);

for (int i = porIntLeft; i < porIntRight; i++) {

String url = "*URL GOES HERE*/new?x=" + String.valueOf(ValoresX.get(i)) + "&y=" + String.valueOf(ValoresY.get(i)) + "&z=" + String.valueOf(ValoresZ.get(i)) + "&label=\"" + Label + "\"";


StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
});
queue.add(stringRequest);


I have this running inside a thread since at the same time im displaying a ProgressDialog.

Answer Source

Are you sending 4500 HTTP requests? Of course it takes a lot of time. Instead collect your data and put it in a json document for instance. And send that document in one HTTP request (of course if you can change your backend to allow that).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download