🌟 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> call, Response> 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!

To continue reading this premium tutorial go to futurestud.io!

Please follow and like us: