harmony 鸿蒙Removing Sticky Common Events (for System Applications Only)
Removing Sticky Common Events (for System Applications Only)
When to Use
Subscribers can receive sticky common events that have been sent. If the events are no longer forwarded, the event publisher needs to remove them. The system provides an API for removing sticky common events.
Available APIs
For details, see API Reference.
API | Description |
---|---|
removeStickyCommonEvent(event: string, callback: AsyncCallback<void>): void | Removes a sticky common event. |
How to Develop
Declare the ohos.permission.COMMONEVENT_STICKY permission. For details, see Declaring Permissions.
Import the module.
import { BusinessError, commonEventManager } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG: string = 'ProcessModel';
const DOMAIN_NUMBER: number = 0xFF00;
- Call removeStickyCommonEvent() to remove the corresponding sticky common event.
NOTE
The sticky common event to be removed must have been released by the application. For details about how to publish sticky common events, see Publishing Common Events.
// Remove the sticky common event. Replace the event field with the actual event name.
commonEventManager.removeStickyCommonEvent('event', (err: BusinessError) => {
// sticky_event indicates the name of the target sticky common event.
if (err) {
hilog.error(DOMAIN_NUMBER, TAG, `Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`);
return;
}
//...
hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in removing sticky event.`);
});
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Process and Thread Communication
harmony 鸿蒙Introduction to Common Events
harmony 鸿蒙Publishing Common Events
harmony 鸿蒙Subscribing to Common Events in Static Mode (for System Applications Only)
harmony 鸿蒙Common Event Subscription Overview
harmony 鸿蒙Subscribing to Common Events in Dynamic Mode
harmony 鸿蒙Unsubscribing from Common Events in Dynamic Mode
harmony 鸿蒙Using Emitter for Inter-Thread Communication
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦