@Deprecated
public class ProtectedUnPeekLiveDataV3<T>
extends androidx.lifecycle.LiveData<T>
https://juejin.im/post/5dafc49b6fb9a04e17209922
本类参考了官方 SingleEventLive 的非入侵设计,
TODO:并创新性地引入了 "延迟清空消息" 的设计, 如此可确保: 1.一条消息能被多个观察者消费 2.延迟期结束,不再能够收到旧消息的推送 3.并且旧消息在延迟期结束时能从内存中释放,避免内存溢出等问题 4.让非入侵设计成为可能,遵循开闭原则
TODO:增加一层 ProtectedUnPeekLiveData, 用于限制从 Activity/Fragment 推送数据,推送数据务必通过唯一可信源来分发, 如果这样说还不理解,详见: https://xiaozhuanlan.com/topic/6719328450 和 https://xiaozhuanlan.com/topic/0168753249
Create by KunMinX at 19/9/23
| 限定符和类型 | 字段和说明 |
|---|---|
protected int |
DELAY_TO_CLEAR_EVENT
已过时。
|
protected boolean |
isAllowNullValue
已过时。
|
protected boolean |
isAllowToClear
已过时。
|
| 构造器和说明 |
|---|
ProtectedUnPeekLiveDataV3()
已过时。
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
observe(androidx.lifecycle.LifecycleOwner owner,
androidx.lifecycle.Observer<? super T> observer)
已过时。
|
void |
observeForever(androidx.lifecycle.Observer<? super T> observer)
已过时。
UnPeekLiveData 主要用于表现层的 页面转场 和 页面间通信 场景下的非粘性消息分发,
出于生命周期安全等因素的考虑,不建议使用 observeForever 方法,
对于数据层的工作,如有需要,可结合实际场景使用 MutableLiveData 或 kotlin flow。
|
protected void |
setValue(T value)
已过时。
重写的 setValue 方法,默认不接收 null
可通过 Builder 配置允许接收
可通过 Builder 配置消息延时清理的时间
override setValue, do not receive null by default
You can configure to allow receiving through Builder
And also, You can configure the delay time of message clearing through Builder
|
protected int DELAY_TO_CLEAR_EVENT
protected boolean isAllowNullValue
protected boolean isAllowToClear
public void observe(@NonNull
androidx.lifecycle.LifecycleOwner owner,
@NonNull
androidx.lifecycle.Observer<? super T> observer)
observe 在类中 androidx.lifecycle.LiveData<T>public void observeForever(@NonNull
androidx.lifecycle.Observer<? super T> observer)
对于数据层的工作,如有需要,可结合实际场景使用 MutableLiveData 或 kotlin flow。
observeForever 在类中 androidx.lifecycle.LiveData<T>observer - protected void setValue(T value)
override setValue, do not receive null by default You can configure to allow receiving through Builder And also, You can configure the delay time of message clearing through Builder
setValue 在类中 androidx.lifecycle.LiveData<T>value -