Move
//Gets a object containing some configurations Call<Configs> callC = contactInterface.getConfigs(Configs); callC.enqueue(new Callback<Configs>() { @Override public void onResponse(Response<Configs> response, Retrofit retrofit) { // Fetch the Configs object and save it on the database Intent loginact = new Intent(TokenActivity.this, LoginActivity.class); startActivity(loginact); } @Override public void onFailure(Throwable t) { Log.i("TAG", "Error: " + t.getMessage()); } });
inside callM
onResponse
method similar to this. Thus, firs callM
will execute, whenever callC
ends, it will execute, and whenever callC
ends, it will drop the intent.
getContact(){ //Get a contact List from the server Call<List<ModelContact>> callM = contactInterface.createRContact(listContact); callM.enqueue(new Callback<List<ModelContact>>() { @Override public void onResponse(Response<List<ModelContact>> response, Retrofit retrofit) { // Fetch the List from Response and save it on the local database //Gets a object containing some configurations Call<Configs> callC = contactInterface.getConfigs(Configs); callC.enqueue(new Callback<Configs>() { @Override public void onResponse(Response<Configs> response, Retrofit retrofit) { //Fetch the Configs object and save it on the database //Here I need to start a new activity after the calls Intent loginact = new Intent(TokenActivity.this, LoginActivity.class); startActivity(loginact); } @Override public void onFailure(Throwable t) { Log.i("TAG", "Error: " + t.getMessage()); } }); } @Override public void onFailure(Throwable t) { Log.i("TAG", "Error: " + t.getMessage()); } }); }
source share