Does Retrofit make network calls on main thread?

前端 未结 3 783
轮回少年
轮回少年 2020-11-30 01:03

I am trying to explore Retrofit+OkHttp on Android. Here\'s some code I found online :

RestAdapter restAdapter = new RestAdapter.Builder().setExecutors(execu         


        
3条回答
  •  北海茫月
    2020-11-30 01:49

    The method that return a value does it Synchronously.

    @GET("/user/{id}/asset")
    Asset getUserAsset(@Path("id") int id);
    

    To do it Asynchronous all you need is to add a Callback.

    @GET("/user/{id}/asset")
    void getUserAsset(@Path("id") int id, Callback cb);
    

    Hope this Helps.

    Regards!

提交回复
热议问题