Retrofit 2 — Custom Call Adapter to Separate OnResponse Callback

In the last tutorial we've introduced Retrofit call adapters. In this tutorial, you'll benefit from learning how to implement a custom call adapter, and you'll see how to separate the onResponse callback into more useful callbacks.

By the end of the tutorial, you won't need to write this boilerplate code anymore:

public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {  
    Toast.makeText(CallAdapterActivity.this, "Response from server ...", Toast.LENGTH_SHORT).show();

    if (response.isSuccessful()) {
        Toast.makeText(CallAdapterActivity.this, "... which is successful!", Toast.LENGTH_SHORT).show();
    }
    else {
        Toast.makeText(CallAdapterActivity.this, "... which is bad :(", Toast.LENGTH_SHORT).show();
    }
}

Let's get started right away, it's a lot of work, but it'll be worth your time!

Retrofit Series Overview


Continue reading

University Enrollment Required

Future Students benefit from value packed videos and tutorials.

Enroll to receive exclusive content or sign in if you’re already a Future Student.

Enroll me for $15/mo

Explore the Library

Find interesting tutorials and solutions for your problems.