Asynchronous versions 1.9 and 2.0 have a difference.
/ * Synchronous in version 1.9 * /
public interface APIService { @POST("/list") Repo loadRepo(); }
/ * Asynchronous in version 1.9 * /
public interface APIService { @POST("/list") void loadRepo(Callback<Repo> cb); }
But on Retrofit 2.0, it's a lot easier, since you can only declare with one template.
public interface APIService { @POST("/list") Call<Repo> loadRepo(); }
// Synchronous call when retrofitting 2.0
Call<Repo> call = service.loadRepo(); Repo repo = call.execute();
// Asynchronous call when retrofitting 2.0
Call<Repo> call = service.loadRepo(); call.enqueue(new Callback<Repo>() { @Override public void onResponse(Response<Repo> response) { Log.d("CallBack", " response is " + response); } @Override public void onFailure(Throwable t) { Log.d("CallBack", " Throwable is " +t); } });
Mehrdad Faraji Sep 16 '15 at 16:34 2015-09-16 16:34
source share