ILifecycleObserverpublic interface LifecycleStateObserver extends ILifecycleObserver
Lifecycle dispatches a lifecycle change event to a registered LifecycleStateObserver.
LifecycleStateObserver observes lifecycle changes, and onStateChanged(ohos.aafwk.ability.Lifecycle.Event,ohos.aafwk.content.Intent) is
called back to process lifecycle change events. Same as LifecycleObserver, the
LifecycleStateObserver interface can also implement lifecycle callbacks for Ability and
AbilitySlice. LifecycleStateObserver is more suitable to act as the observer of a specific
lifecycle event. For example, ActiveData can use this interface to
observe lifecycle changes of an ability or ability slice. The system stops notifying
LifecycleStateObserver when the ability or ability slice enters the BACKGROUND state and resumes
the notification when the state changes to ACTIVE.
You can call Lifecycle#addObserver(ILifecycleObserver) to register a LifecycleStateObserver
with Lifecycle. The onStateChanged(ohos.aafwk.ability.Lifecycle.Event,ohos.aafwk.content.Intent) method is called back after the
callback methods in Ability and AbilitySlice.
LifecycleStateObserver is more flexible than LifecycleObserver. It can observe changes of all
lifecycle states or a specific state. You are advised to use LifecycleStateObserver as the observer to
observe state changes in both the foreground and background.
Lifecycle,
ILifecycleObserver,
LifecycleObserverSystemCapability.Aafwk#ABILITY| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
onStateChanged(Lifecycle.Event event,
Intent intent) |
Called back in response to a lifecycle change.
|
void onStateChanged(Lifecycle.Event event, Intent intent)
LifecycleStateObserver each time the lifecycle state changes.event - Indicates the lifecycle event.intent - Indicates the state change information.