android - 如何在 Activity 中使用 Retrofit 和 RxJava/RxAndroid 处理旋转?

标签 android rotation retrofit rx-java rx-android

我读过 here我们可以使用一些全局缓存来处理旋转。

You can prevent this by using the cache or replay Observable operators, while making sure the Observable somehow survives the Activity life-cycle (for instance, by storing it in a global cache, in a Fragment, etc.)

但是如何实现呢?有人可以给我举个例子怎么做? 或者您知道一些更好的方法来处理配置更改?

编辑:

目前我已经找到了很多方法,但最终还是使用了 RxBus 实现。你可以找到使用 RxBus 的好例子 here .

最佳答案

我制作了一个演示应用程序 (https://github.com/pmellaaho/RxApp) 来试验如何处理 Android 应用程序中的各种情况。简而言之,我使用来自 Activity 的单例模型来获取来自网络的响应。这使得缓存响应、访问来自多个 UI 组件的数据、订阅挂起的请求以及为自动化 UI 测试提供模拟数据成为可能。

关于android - 如何在 Activity 中使用 Retrofit 和 RxJava/RxAndroid 处理旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32243428/

相关文章:

android - 如何在 Horizo​​ntal RecyclerView 中最后显示部分项目以指示滚动?

android - 有没有更好的方法将私有(private) MutableLiveData 公开为 ViewModel 的 LiveData。 [安卓、 Kotlin ]

java - 阵列矩形旋转

java - Android 单个观察者,在不同的类中有多个订阅者

android - 将 CookieHandler 与 OkHttp 和 Retrofit 2 一起使用

java - 为什么我来自 Android 的 UDP 消息不起作用?

Android:带 URL 的 openInputStream 抛出 FileNotFoundException

OpenGl在Y轴上旋转对象以查看另一个对象

html - 在不旋转控件的情况下旋转 HTML 5 视频?

java - 无法从嵌套json改造android studio中获取值(value)