Detailed explanation of rxjava2 retrofit2 network framework, simple and lightweight packaging

preface

Rxjava2 and retrofit2 have been popular for some time. Some time ago, relevant technologies in this regard were introduced to the company's projects. Here are the ideas of relevant packaging.

demand

Understand what needs to be met before packaging.

rely on

Rxjava2 connects retrofit2

First encapsulate the management class of a network framework to facilitate calling

Restful style interface

The basic type returned by the server. Special attention should be paid to distinguishing the response type when importing the class

Fastjson support

Because fastjson is used in the project, square has not yet implemented its support for fastjson, but retains the code extension. You can package the fastjson converter yourself.

Unified data return processing

The exception handling class is added below

Asynchronous request join loading dialog

At this time, we can extend baseobserver according to the uniformly encapsulated dialog in our project

Add a scheduling class to facilitate thread switching and solve the problem of memory leakage

After talking so much, how to use this package? Let's see how to use it.

Is the encapsulated code more concise? The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>