简体   繁体   中英

How to use retrofit2 + rxjava2 mvp android

How to use retrofit2 + rxjava2 in android

I want to learn about sent parameter to server and get data from server with retrofit2 + rxjava2

Can you get some example for me? thanks!

Please check this blog. It could take some time to understand about mvi and immutable states, but it is based on rxjava2, has retrofit examples and overall architecture of application http://hannesdorfmann.com/android/model-view-intent

But mvp quite well explained here: http://hannesdorfmann.com/mosby/first-app/ Using mosby as library

There are a lot of guides over the network describing MVP pattern,Reactive-programing and Retrofit.

First you should understand what is the idea of the MVP pattern stands for(Model-View-Presenter).

Shortly the idea will be: in most cases your view needs some data from the beck-end and when it's received to be populated for the user. Using MVP pattern you will have something like this:

View needs some data and for that is invoking the presenter then presenter is invoking the model

在此处输入图片说明

The model in your case can represents a Repository with a Service(Retrofit) or DAO The return result should be some observable(RxJava2) And with a few words you will have something like this:

**Getting some data from server:** View -> Presenter -> Repository -> Service **Receiving the data from server:** Response -> Presenter -> View

Note that this is a very high-level of explanation, my advise will be to read carefully about the MVP,RxJava2 and Retrofit separately and when you feel you are ready to try combine it withing one project.

You can find some info about RxJava2 + Retrofit2 here: https://android.jlelse.eu/implementing-rxjava2-retrofit2-for-better-performance-during-api-calls-fe1c53e1f939

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM