How to know when a retrofit call is completed in order to start an Activity?

Asked

Viewed 83 times

1

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

I need to know when those two calls are finished, so I can call a new one activity, however, I put two variables of the type boolean in the onResponse of each of the two calls to perform a test as:

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

When the code reaches the test, the calls have not yet received the response from the server, making the two variables false, and not starting to Activity. How can I make that code open the new activity run only after both calls are completed?

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 ways at the end will know the moment to call

Browser other questions tagged

You are not signed in. Login or sign up in order to post.