There is a database with data, in turn I take the data and pass it to the request. It is necessary to perform enumeration of all data, that is, send conditionally 7 requests in a row, receiving a response from the server to check what has come, if the error continues, if the normal response is to finish sending the requests. Tried through a while , nothing happened. Tell me please.

  public void methodWhile(){ while (true){ macc = arrayMac[d]; mRquest(macc); Log.d("qwe", "Ответ с сервера = " + code); if (code == 1 || code == 2){ Log.d("qwe","true"); schag++; d++; Log.d("qwe", "Кол-во шагов " + schag); // break; } else { Log.d("qwe","false"+ "" + code); break; } } } public void mRquest(String bmac){ Map<String, String> query = new HashMap<String, String>(); query.put("bmac",bmac); query.put("cmac", mydeviceAddress); query.put("rsi", "-50"); //Response response = service.search(parameters); Log.d("qwe", "Map Created"); apiService.search(query); Call<Example> call = apiService.search(query); call.enqueue(new Callback<Example>() { @Override public void onResponse(Call<Example> call, Response<Example> response) { if (response.isSuccessful()) { Example mExample = response.body(); Log.d("qwe", "Запрос выполнился успешно"); } else { Log.d("qwe", "Сервер вернул ошибку"); } } @Override public void onFailure(Call<Example> call, Throwable t) { Log.d("qwe", "Произошла ошибка при выполненни запроса"); } }); } 
  • one
    and what kind of mistake was it? - plesser
  • What did you specify in the cycle? How do you make requests in the database? - Nikotin N
  • I used retrofit, the error was in logic, I just don’t know how to send the response back to the loop in order to understand whether to stop the loop or not. - IgorDenis
  • I have not connected the database yet, I am taking the data from the array of strings. - IgorDenis

1 answer 1

Try using RealTime database from google itself, called Firebase . You get the data there via an asynchronous request (all at once in the snapshot'e, and then work with them as you like - read, sort, update), you no longer have to wait for a response from the database. P.S. do you understand that in the case of the constant sending of requests to the database can get ANR ?