I have to send some things from the database to the server. So, I call a db method, and get a cursor, which has many positions. I need to send a httprequest for avery position of the cursor, but only send the second petition when the first has been received in the server, and the proper answer sent. I have this code:
final Cursor cursor = db.getData();
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
if(cursorContadores.moveToFirst()){
do{
Call<String> peticion = interfaz.saveToServer(cursor.getString(1), cursor.getString(2));
peticion.enqueue(new Callback<String>() {
@Override
public void onResponse(Response<String> response, Retrofit retrofit) {
if(response.message().equals("ok")){
}else{
}
}
@Override
public void onFailure(Throwable t) {
}
});
}while (cursorContadores.moveToNext());
cursorContadores.close();
db.close();
}
}
});
thread.start();
This way, I think it will not wait until every iteration in the do while block ends, to start the next iteration.
How could I achieve this? Something I could read to learn how to?
Thank you.