我读过 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/