1# Unsubscribing from Common Events in Dynamic Mode
2
3
4## When to Use
5
6After a service is finished in the dynamic mode, the subscriber should proactively unsubscribe from the event. You can call [unsubscribe()](../../reference/apis-basic-services-kit/js-apis-commonEventManager.md#commoneventmanagerunsubscribe) to unsubscribe from a common event that is no longer required.
7
8
9## Available APIs
10
11| API| Description|
12| -------- | -------- |
13| unsubscribe(subscriber:&nbsp;[CommonEventSubscriber](../../reference/apis-basic-services-kit/js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber),&nbsp;callback?:&nbsp;AsyncCallback<void\>) | Unsubscribes from a common event.|
14
15
16## How to Develop
17
181. Import the **commonEventManager** module.
19
20   ```ts
21   import { BusinessError, commonEventManager } from '@kit.BasicServicesKit';
22   import { hilog } from '@kit.PerformanceAnalysisKit';
23
24   const TAG: string = 'ProcessModel';
25   const DOMAIN_NUMBER: number = 0xFF00;
26   ```
27
282. Subscribe to an event by following the procedure described in [Subscribing to Common Events in Dynamic Mode](common-event-subscription.md).
29
303. Call [unsubscribe()](../../reference/apis-basic-services-kit/js-apis-commonEventManager.md#commoneventmanagerunsubscribe) in **CommonEvent** to unsubscribe from an event.
31
32   ```ts
33   // The subscriber object is created during event subscription.
34   if (subscriber !== null) {
35     commonEventManager.unsubscribe(subscriber, (err: BusinessError) => {
36       if (err) {
37         hilog.error(DOMAIN_NUMBER, TAG, `UnsubscribeCallBack err = ${JSON.stringify(err)}`);
38       } else {
39         hilog.info(DOMAIN_NUMBER, TAG, `Unsubscribe success`);
40         subscriber = null;
41       }
42     })
43   }
44   ```
45