Is there a way of know when my Retrofit call has finished it's duty? I like know when all the data is received so the code can move on, like starting another activity or use data from the first call to make a second?
Ps.: I'm 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);
}
Perhaps you can use two boolean flags and start the new intent outside of your getContact method.
Something like this:
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With