SingleLiveEvent 实际上是 Android 架构组件库的一部分吗? [英] Is SingleLiveEvent actually part of the Android Architecture Components Library?
问题描述
我一直在使用 SingleLiveData
类,该类可以在 这里.我的问题是:
I have been using the SingleLiveData
class which can be found here. My questions are:
SingleLiveData
实际上是 Android 架构组件的一部分吗?
Is
SingleLiveData
is actually part of the Android Architecture Components?
使用它是个好主意吗?
推荐答案
看实时数据及其父/子继承 没有 SingleLiveData 这样的东西.阅读@Raghu 提供的链接,我找到了声明:
Looking at Live data and its Parent/Children inheritance there is no such thing as SingleLiveData. Reading link provided by @Raghu, I find statement:
SingleLiveEvent 类是为示例创建的,作为适用于该特定场景的解决方案.它是一个 LiveData,只会发送一次更新.
The SingleLiveEvent class was created for a sample as a solution that worked for that particular scenario. It is a LiveData that will only send an update once.
所以回答你的问题:
SingleLiveData 实际上是 Android 架构组件的一部分吗?
Is SingleLiveData is actually part of the Android Architecture Components?
不,不是!
使用它是个好主意吗?
这取决于很多因素.由于我没有使用它,我将给出一般性的想法.使用您在演示应用程序或其他方式中找到的类可能无法保证更新或修复错误.因此,如果您非常了解该类,可以修复您可能发现的任何错误,并且如果它符合您的需要,请使用它.
This depends on many factors. Since I haven't used it I will give general idea. Using classes that you find in demo app or other way might not be guaranteed to be updated or bug-fixed. So if you understand the class so well that you can fix any bug you might find, and if it fits your need, then use it.
但通常我会避免这种情况,如果我能找到维护良好并且做同样工作的东西.
But generally I would avoid that if I can find something that is well maintained and does the same job.
由于浏览了这篇文章,我觉得他正在尝试制作某种观察者模式,我建议您查看 rxjava
Since from skimming the article I get impression he is trying to make some sort of observer pattern, I will suggest you check out rxjava
这篇关于SingleLiveEvent 实际上是 Android 架构组件库的一部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!