How to know when call forwarding is completed

Is there any way to find out when my revision request completed its work? I like to know when all the data is received so that the code can move on, for example, start another action or use the data from the first call to make the second?

Ps: I am using an asynchronous request (.enqueue).

Edit:

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 } @Override public void onFailure(Throwable t) { Log.i("TAG", "Error: " + t.getMessage()); } }); //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 } @Override public void onFailure(Throwable t) { Log.i("TAG", "Error: " + t.getMessage()); } }); //Here I need to start a new activity after the calls Intent loginact = new Intent(TokenActivity.this, LoginActivity.class); startActivity(loginact); } 
+6
source share
3 answers

Perhaps you can use two Boolean flags and start a new intent outside of your getContact method.

Something like that:

 public class MyActivity extends Activity { //lot of code omitted private boolean cIsFinished; private boolean mIsFinished; private void getContact(){ //create M and C m.onResponse(){ //do whatever you want with data and call startIntent mIsFinished=true; startIntent(); } c.onResponse(){ //do whatever you want with data and call startIntent cIsFinished=true; startIntent(); } } private synchronized void startIntent(){ if(cIsFinished && mIsFinished){ //startIntentHere! Intent intent = new blah blah blah } } } 
+3
source

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()); } }); } 
+1
source

If you have any request that depends on each other, it will be complicated. You can do this with RxJava, using the flatMap method to bind multiple requests and avoid the addon. it's pretty simple. You can find it out here.

http://joluet.imtqy.com/blog/2014/07/07/rxjava-retrofit/

0
source

All Articles