How to implement an async Callback using Square's Retrofit networking library How to implement an async Callback using Square's Retrofit networking library android android

How to implement an async Callback using Square's Retrofit networking library


After some more research and just plain spending more time in the Android/Java world I figured this out, using the example from their docs.

Interface:

@GET("/user/{id}/photo")  void listUsers(@Path("id") int id, Callback<Photo> cb);

Implementation:

RestAdapter restAdapter = new RestAdapter.Builder()            .setServer("baseURL")                 .build();ClientInterface service = restAdapter.create(ClientInterface.class);Callback callback = new Callback() {    @Override    public void success(Object o, Response response) {    }    @Override    public void failure(RetrofitError retrofitError) {    }};service.listUsers(666, callback);