Basic use of Android Retrofit

What is Retrofit Retrofit is a popular network request framework now. It can be understood as an enhanced version of okhttp, with Okhttp encapsulated at the bottom. To be precise, Retrofit is an encapsulation of a RESTful http network request framework. Because the network request work is essentially completed by okhttp, and Retrofit is responsible […]

Retrofit’s good friend-RetrofitAssistant plug-in

Foreword Do you encounter the following problems when using Retrofit: When you need to find/navigate to a certain interface, use the global search URL and search through a dazzling pile of useless results. Sometimes you have to turn several pages to find it. After writing or modifying the interface, I found that the request was […]

Basic use of Retrofit

Configuration val retrofit: Retrofit = Retrofit.Builder() .baseUrl(“http://baidu.com”) .client(getOkHttpClient()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .callbackExecutor(Executors.newSingleThreadExecutor())//The thread pool of the callback in call does not set the default callback Android main thread //When calling create on a Retrofit instance, whether to immediately generate dynamic proxy implementation cache for all methods in the interface. false will be generated when used, true […]

OkHttp+Retrofit+RxJava is easy to understand

1.Easy to use //Add reference in build.gradle implementation(“io.reactivex.rxjava2:rxjava:2.2.0”) implementation(“com.squareup.retrofit2:retrofit:2.2.0”) implementation(“com.squareup.retrofit2:converter-gson:2.2.0”) implementation(“com.squareup.retrofit2:adapter-rxjava2:2.2.0”) implementation(“com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0”) implementation(“io.reactivex.rxjava2:rxandroid:2.0.1”) implementation(“com.squareup.okhttp3:logging-interceptor:3.4.1”) //retrofit statement var api = Retrofit.Builder() .client(client) //Data analysis class can be customized. Retrofit2 must be specified, otherwise an error will be reported .addConverterFactory(GsonConverterFactory.create()) //Do not call this method or do not pass in RxJava2CallAdapterFactory. The method declared in apiService cannot […]

Android Retrofit custom GsonConverterFactory

During project development, the format returned by the background does not have a unified return format (the return formats of success and failure are inconsistent). Case description: Login business json (when successful) { “code”: 0, “message”: “Login successful”, “data”: { “name”: “admin”, “token”: “ad987810544564310” } } Login business json (when failed) { “code”: 0, “message”: […]

Android Retrofit Low Intrusive Tips

Retrofit low-invasive tips Common development requirements Requirement 1: When Kotlin uses Retrofit to call the coroutine interface, it always needs to handle network exceptions. Requirement 2: When using Retrofit to make interface calls, perform unified error handling Tips Retrofit version needs to be 2.6.0 and above API data model and data interface are based on […]

Simple GET request using Retrofit in Android

The web is a key factor in mobile development. Most, if not all, mobile apps include the web to some extent. The application is sending or receiving information. Initially, developers handled networking in the main thread. This made the application less user-friendly because the screen would “freeze”. After the Honeycomb release, networking on the main […]

Coroutines in Kotlin – Create main thread-safe functions from blocking code & coroutines in Room and Retrofit

1. Create main thread-safe functions from blocking code Through this chapter, you will learn how to switch running coroutines to implement a working version of TitleRepository. 1.1. View the existing callback code in refreshTitle Open TitleRepository.kt and view the existing callback-based implementation. TitleRepository.kt // TitleRepository.kt fun refreshTitleWithCallbacks(titleRefreshCallback: TitleRefreshCallback) { // This request will be run […]

Android tracking strategy + Retrofit upload tracking data

Android hiding place In enterprise-level Android projects, tracking is an important technology used to collect user behavior data for analysis and product improvement. The following is a common buried solution used in Android enterprise-level project development: Define buried events: First, determine the key events that need to be buried, such as page visits, button clicks, […]