android-databinding - LiveData 与 Observable 数据对象

标签 android-databinding android-livedata android-jetpack

根据LiveData documentation ,其中一项功能旨在使用可观察模式通知数据更改。
(除此之外,LiveData 还提供了许多其他有前途的功能)

另一方面,Observable data object基于其 documentation能够通知其他人其数据的变化。

因此,这两个功能似乎是相同的。

问题是:

LiveData不是更好吗?它的其他功能?

最佳答案

根据 LiveData 文档:

LiveData is an observable data holder class. Unlike a regular observable, LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services. This awareness ensures LiveData only updates app component observers that are in an active lifecycle state.



所以它本质上是一个 生命周期感知 observable,现在它是一个优势,不是吗?
但是,对于仅使用 RxJava 确实没有任何限制。或 LiveData ,两者可以一起使用。

实际上,当没有可用的生命周期(如 )时,最好使用 RxJava。存储库 在数据层并保留 LiveData在生命周期很重要的层中,例如 介绍 层。

关于android-databinding - LiveData 与 Observable 数据对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53572489/

相关文章:

android - 数据绑定(bind)按钮onclick不起作用

android - 错误 : <identifier> expecte when setting up binding adapters for two way data binding

android - 我们如何获取数据绑定(bind)以使用保存的实例状态?

android - MVVM:复杂 View / View 模型-> 多个 LiveData 对象?

android - 如何在 Jetpack Compose 中从 Alignment.Start 到 Align.End 设置动画?

android - JetPack Compose 禁用 BottomSheet 外部触摸

android - 销毁时如何从 Activity 中解除绑定(bind)viewModel

java - "Cannot access database on the main thread"AsyncTask异常

android-room - 从android Room Architecture Component中的多对多结构中获取LiveData

android - (导航组件)返回首页fragment时如何在activity上显示返回箭头?