android – 如何知道Retrofit调用何时完成

android – 如何知道Retrofit调用何时完成,第1张

概述有没有办法知道我的改装电话何时完成了它的职责?我喜欢知道什么时候收到所有数据,所以代码可以继续,比如开始另一个活动或者使用第一次调用的数据做一秒钟? Ps.:我正在使用异步请求(.enqueue). 编辑: getContact(){ //Get a contact List from the server Call<List<ModelContact>> callM = co 有没有办法知道我的改装电话何时完成了它的职责?我喜欢知道什么时候收到所有数据,所以代码可以继续,比如开始另一个活动或者使用第一次调用的数据做一秒钟?

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调用何时完成所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1136092.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存