Event Subscription Overview

Event Description

The HiAppEvent module can be used to subscribe to application events and system events.

Application Events

Application events are defined by developers. For example, a button click event. The fields contained in the params object of an application event come from the application. You can customize the fields through the write API. You can determine the field meanings as required.

System Events

System events occur during application running, such as performance, power consumption, and stability issues. The fields contained in the params object of system events are defined by the system services. In addition, you can add custom parameters to the params object for crash events and application freeze events through the setEventParam API.

For details about the supported system events, detection principles, and fields in params, see the related topics.

Crash Event Overview

Application Freeze Event Overview

Resource Leak Event Overview

Address Sanitizer Event Overview

Main Thread Jank Event Overview

Task Execution Timeout Event Overview

Application Killed Event Overview

ArkWeb Fling Jank Event Overview

Event Subscription Methods

HiAppEvent provides the addWatcher API for subscribing to system events. The following subscription methods are supported:

Method 1: Set triggerCondition to implement the onTrigger() callback. When the callback conditions are met, the system automatically triggers the callback.

Method 2: If the triggerCondition parameter is not set, use the holder object returned by the event subscription to obtain the subscribed event.

NOTE

If the event is not generated or the log information is not captured, the query result may be empty. In this case, you are advised to call the query interface for multiple times.

Method 3: Implement the onReceive() callback, which is triggered in real time when the subscribed event occurs.

For details about event subscription using ArkTS APIs, see hiAppEvent.addWatcher. The C/C++ event subscription APIs support only method 1 and method 3. For details, see Subscribing to an Event.