Ps.:我正在使用异步请求(.enqueue).
编辑:
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);}解决方法 也许您可以使用两个布尔标志并在getContact方法之外启动新意图.
像这样的东西:
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 } } }总结
以上是内存溢出为你收集整理的android – 如何知道Retrofit调用何时完成全部内容,希望文章能够帮你解决android – 如何知道Retrofit调用何时完成所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)