harmony 鸿蒙Unsubscribing from Common Events in C

  • 2025-06-06
  • 浏览 (5)

Unsubscribing from Common Events in C

When to Use

After completing service requirements, subscribers need to unsubscribe from common events.

Available APIs

For details about the APIs, see CommonEvent.

API Description
CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber) Creates the subscriber information.

How to Develop

  1. Reference header files.
   #include <cstdint>
   #include "hilog/log.h"
   #include "BasicServicesKit/oh_commonevent.h"
  1. Add dynamic link libraries to the CMake script.
   target_link_libraries(entry PUBLIC
       libace_napi.z.so
       libhilog_ndk.z.so
       libohcommonevent.so
   )
  1. Unsubscribe from a common event.

After a subscriber subscribes to a common event and meets service requirements, the subscriber can use OH_CommonEvent_UnSubscribe to unsubscribe from the event.

   void Unsubscribe(CommonEvent_Subscriber* subscriber) {
       // Unsubscribe from a common event by passing a subscriber.
       int32_t ret = OH_CommonEvent_UnSubscribe(subscriber);
       OH_LOG_Print(LOG_APP, LOG_INFO, 1, "CES_TEST", "OH_CommonEvent_UnSubscribe ret <%{public}d>.", ret);
   }

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Process and Thread Communication

harmony 鸿蒙Introduction to Common Events

harmony 鸿蒙Publishing Common Events

harmony 鸿蒙Removing Sticky Common Events (for System Applications Only)

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

harmony 鸿蒙Publishing Common Events in C

0  赞