T - Indicates the type of data to observe.public abstract class DataObserver<T> extends Object
ActiveData.
Observers of ActiveData must inherit this class and override the onChanged(java.lang.Object) method. In
this way, ActiveData can notify observers of data changes by using onChanged(java.lang.Object).
DataObserver holds a Lifecycle object by using the setLifecycle(ohos.aafwk.ability.Lifecycle) method. The
object indicates the lifecycle of the matching Ability or AbilitySlice. DataObserver also
allows ActiveData to observe its lifecycle changes. Therefore, DataObserver and ActiveData
observe each other. DataObserver observes data changes of ActiveData, and ActiveData
observes lifecycle changes of DataObserver.
SystemCapability.Aafwk#ABILITYJET| 构造器 | 说明 |
|---|---|
DataObserver() |
public abstract void onChanged(T value)
Observers of ActiveData must implement this method so that they can be notified upon data changes.
value - Indicates the new value of the data being observed. This parameter cannot be null.public final void setLifecycle(Lifecycle owner)
The ActiveData object will be notified when the lifecycle state of an observer changes.
owner - Indicates the lifecycle state of the observer. This parameter cannot be null.IllegalArgumentException - invalid parameterIllegalStateException - invalid lifeOwner