Read More

Android Retrofit 2 custom callback

Retrofit 2 is one the best library I have used it so far. There are many cases in which we can use custom callback for our response callback such as Error Handling, Response Handling, Custom Response and much more.

By using a custom callback or any piece of custom code in an application we are promoting object oriented design pattern and thus reducing your efforts that are needed/mandatory to follow if not using it.

Here is an example of Custom Callback that is used to handle error , hide dialog  and return response data to original callback.

 

How it is helpful?

By using Custom Callback, we are preventing from extra effort required to handle error in each request. Plus, we can perform custom operation that are required whenver the response is recieved. In this case we are just hidding the AlertDialog.

We can use this callback instead of our existing callback. e.g.

And Here is the original callback which gets called from our Custom RetrofitCallback

 

That’s all it take for laziness!

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close