简体   繁体   English

如何使用retrofit2 + rxjava2 mvp android

[英]How to use retrofit2 + rxjava2 mvp android

How to use retrofit2 + rxjava2 in android如何在android中使用retrofit2 + rxjava2

I want to learn about sent parameter to server and get data from server with retrofit2 + rxjava2我想了解发送的参数到服务器并使用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了解 mvi 和不可变状态可能需要一些时间,但它基于 rxjava2,具有改造示例和应用程序的整体架构http://hannesdorfmann.com/android/model-view-intent

But mvp quite well explained here: http://hannesdorfmann.com/mosby/first-app/ Using mosby as library但是 mvp 在这里得到了很好的解释: 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.网络上有很多指南描述了 MVP 模式、反应式编程和改造。

First you should understand what is the idea of the MVP pattern stands for(Model-View-Presenter).首先,您应该了解MVP 模式所代表的思想(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:使用 MVP 模式,您将拥有如下内容:

View needs some data and for that is invoking the presenter then presenter is invoking the model View需要一些数据,因为它正在调用presenter然后演示者正在调用模型

在此处输入图片说明

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:您的案例中的模型可以表示带有Service(Retrofit) or DAORepository返回结果应该是一些可观察的(RxJava2)并且只需几句话,您就会得到如下内容:

**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.请注意,这是一个非常高级的解释,我的建议是分别仔细阅读MVP,RxJava2 and Retrofit ,当您准备好尝试将其与一个项目结合起来时。

You can find some info about RxJava2 + Retrofit2 here: https://android.jlelse.eu/implementing-rxjava2-retrofit2-for-better-performance-during-api-calls-fe1c53e1f939您可以在此处找到有关 RxJava2 + Retrofit2 的一些信息: https ://android.jlelse.eu/implementing-rxjava2-retrofit2-for-better-performance-during-api-calls-fe1c53e1f939

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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