> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> 本模块首批接口从API 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Extension的上下文环境,继承自Context。
Implements extension context. This module is inherited from **Context**.
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
| options | [ConnectOptions](#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
-返回值
-Return value
| 类型 | 说明 |
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| number | 返回一个number,后续根据这个number去断开连接。 |
| number | A number, based on which the connection will be interrupted.|
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
| context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.|
## onCreate
## onCreate
onCreate(want: Want): void;
onCreate(want: Want): void;
Extension生命周期回调,在创建时回调,执行初始化业务逻辑操作。
Called when an extension is created to initialize the service logic.
Called after **onCreate** is invoked when an ability is started by calling **startAbility**. The value of **startId** is incremented for each ability that is started.
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
| startId | number | 是 | 返回拉起次数。首次拉起初始值返回1,多次之后自动递增。 |
| startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
Called after **onCreate** is invoked when an ability is started by calling **connectAbility**. A **RemoteObject** object is returned for communication with the client.