Có cách nào để biết khi nào cuộc gọi Retrofit của tôi đã hoàn thành nhiệm vụ của nó? Tôi thích biết khi nào tất cả dữ liệu được nhận để mã có thể di chuyển, như bắt đầu một hoạt động khác hoặc sử dụng dữ liệu từ cuộc gọi đầu tiên để thực hiện một giây?Làm thế nào để biết khi nào một cuộc gọi Retrofit được hoàn thành
Ps .: Tôi đang sử dụng yêu cầu không đồng bộ (.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);
}
bạn có thể cung cấp cho đại biểu để enqueue (aka người nghe). – Blackbelt
Tôi có thể tìm thấy mẫu mã ở đâu, tôi đã goggled nó và không tìm thấy gì ... – Rafael
tại sao bạn không đăng nỗ lực của mình? – Blackbelt