![]() ![]() When a successful response is received from the server, the quote is displayed otherwise a retry button is shown with an error message. In the code below, the service gets created and the activity asynchronously calls getQuoteOfTheDay(). Android Stduio : Flamigo SDK : Android 13 Tiramisu compile SDK : 33 Gradle JDK : 17.0.6 Gradle Version: 7.3.3 Gradle plugin : 7.2.2 kotlin plugin : 1.7.0 Dependency (retrofit2 dependency. Ensure your activity calls the Retrofit Service that you have just created. ![]() Public interface QuoteOfTheDayRestService getQuoteOfTheDay() Create a Rest Service interface that will be used with Retrofit.We will also look at testing these failure mechanisms. We will also add a failure mechanism to the front end to show the user a retry button if something goes wrong. In this example, we will look at creating an app that retrieves a quote of the day from a web service and displays it to the user. What if your server goes down for a while? Does your app fall over with it – or does it gracefully recover? Things like this are difficult to emulate with real servers, which is why mocking responses is such a great way to ensure your app is awesome. In order to test your Android apps, one thing that normally gets frequently overlooked is the apps ability to handle different server responses. After trying out Retrofit 2, I have adjusted the previous sample and managed to achieve the same results (with some improvements □). This mechanism works well for Retrofit versions 1.9 and below but has its drawbacks. In the previous post, I discussed implementing a custom Retrofit Client to mock out different HTTP response codes.
0 Comments
Leave a Reply. |