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