标签:rap setvalue EDA super 方法 lifecycle hang abs 生命周期
LiveData.java
------------------------------
@MainThread
public void observeForever(@NonNull Observer<? super T> observer) {
assertMainThread("observeForever");
AlwaysActiveObserver wrapper = new AlwaysActiveObserver(observer);
ObserverWrapper existing = mObservers.putIfAbsent(observer, wrapper);
if (existing != null && existing instanceof LiveData.LifecycleBoundObserver) {
throw new IllegalArgumentException("Cannot add the same observer"
+ " with different lifecycles");
}
if (existing != null) {
return;
}
wrapper.activeStateChanged(true);
}
private class AlwaysActiveObserver extends ObserverWrapper {
AlwaysActiveObserver(Observer<? super T> observer) {
super(observer);
}
@Override
boolean shouldBeActive() {
return true;
}
}
MutableLiveData 继承自 LiveData,把setValue(T) 和 getValue(T) 方法public公开了。
————————————————
标签:rap setvalue EDA super 方法 lifecycle hang abs 生命周期
原文地址:https://www.cnblogs.com/hyhy904/p/11384643.html