Within the cycle while
will not leave you because it is inside the section where the parameters that will be sent in StringRequest
are assigned
As I understand your question, you need to make a request by means of the StringRequest
for each record of your query, for which I recommend that you first do a function that iterates your query, consume another function that is called with each record found, for which I would propose something like this:
Code of the function that generates the results for each request
public void ProcessQuery(){
SQLiteDatabase db = basededatos.getReadableDatabase();
Cursor cursor = db.query("aguacate", new String[] {"calibre","precio","porcentaje","resultado",},null, null, null, null, null);
if (cursor.moveToFirst()) {
//Recorremos el cursor hasta que no haya más registros
do {
final Map<String, String> parameters = new HashMap<String, String>();
parameters.put("calibre",cursor.getString(1));
parameters.put("precio", cursor.getString(2));
parameters.put("porcentaje", cursor.getString(3));
parameters.put("resultado", cursor.getString(4));
//Por cada registro encontrado se obtienen los parámetros y se envían a la función que procesa la petición por medio del StringRequest
ProcessRequest(parameters);
} while(cursor.moveToNext());
}
}
Code of the function that executes the requests
private void ProcessRequest(Map<String, String> parameters){
StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
//Showing toast message of the response
Toast.makeText(upload.this, s , Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
//Showing toast
Toast.makeText(upload.this, volleyError.getMessage(), Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return parameters;
}
};
//Creating a Request Queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
I also recommend that you perform the handling of variables in case one is null and no exception is generated
Update
The varible parameters
is declared as final
so that the code does not mark errors