How do I know when a call of the retrofit is finished in order to start an activity?

1

I have two calls (Call) of Retrofit 2, one that downloads a object of type Config, and one that downloads a list of objects of type Registrations.

I need to know when these two calls are finished, so I can call a new activity , however, if I put two variables of type boolean in onResponse of each of the two calls to perform a test like: / p>

if(var1 && var2 == true){
//Código para abrir a nova activity
}

When the code comes to the test, the calls have not yet received the response from the server, causing the two variables to be false , not starting Activity . How can I make this code to open the new activity run only after the two calls are completed?

    
asked by anonymous 13.01.2016 / 01:14

1 answer

0

In the onResponse method you will know from there just call your activity:

Call<SeuObjeto> call = service.upload(requestBody, nomeProduto, descricaoProduto,email,categoria);
        call.enqueue(new Callback<SeuObjeto>() {
            @Override
            public void onResponse(Call<SeuObjeto> call, Response<SeuObjeto> response) {
                var1 = response.isSuccessful();

            }

Do this in the 2 methods at the end you will know when to call

    
16.06.2016 / 23:08