Defines the structs and APIs of the EmbeddedComponent component option (ArkUI_EmbeddedComponentOption). You can use these APIs to create and dispose of the component option object, and set the exception callback (onError) and normal exit callback (onTerminated) for the EmbeddedComponent component. This applies to scenarios where the EmbeddedUIExtensionAbility component needs to be embedded in an application and its lifecycle needs to be managed, and where exception and normal exit events need to be listened for, helping you flexibly handle state changes during component running.
File to include: <arkui/node_attributes/embedded_component.h>
Library: libace_ndk.z.so
System capability: SystemCapability.ArkUI.ArkUI.Full
Since: 12
Related module: ArkUI_NativeModule
Sample: embedded_component_sample
| Name | typedef Keyword | Description |
|---|---|---|
| AbilityBase_Want | AbilityBase_Want | Declares Want of an ability. |
| ArkUI_EmbeddedComponentOption | ArkUI_EmbeddedComponentOption | Defines the EmbeddedComponentOption parameter for EmbeddedComponent. |
| Name | typedef Keyword | Description |
|---|---|---|
| ArkUI_EmbeddedComponentOption* OH_ArkUI_EmbeddedComponentOption_Create() | - | Creates an EmbeddedComponent option object. |
| void OH_ArkUI_EmbeddedComponentOption_Dispose(ArkUI_EmbeddedComponentOption* option) | - | Disposes of the EmbeddedComponent component option object. |
| void OH_ArkUI_EmbeddedComponentOption_SetOnError(ArkUI_EmbeddedComponentOption* option, void (*callback)(int32_t code, const char* name, const char* message)) | - | Sets the onError callback of the EmbeddedComponent component. This callback is triggered when an exception occurs during the running of the EmbeddedComponent component. |
| void OH_ArkUI_EmbeddedComponentOption_SetOnTerminated(ArkUI_EmbeddedComponentOption* option, void (*callback)(int32_t code, AbilityBase_Want* want)) | - | Sets the onTerminated callback of the EmbeddedComponent component. This callback is triggered when the EmbeddedComponent component exits normally. |
ArkUI_EmbeddedComponentOption* OH_ArkUI_EmbeddedComponentOption_Create()
Description
Creates an EmbeddedComponent component option object. The returned object needs to be disposed of by OH_ArkUI_EmbeddedComponentOption_Dispose when it is no longer used.
Since: 20
Returns
| Type | Description |
|---|---|
| ArkUI_EmbeddedComponentOption* | Pointer to the EmbeddedComponent option object. |
void OH_ArkUI_EmbeddedComponentOption_Dispose(ArkUI_EmbeddedComponentOption* option)
Description
Disposes of the EmbeddedComponent component option object. The object must be created by OH_ArkUI_EmbeddedComponentOption_Create, and it should not be used after being disposed of.
Since: 20
Parameters
| Name | Description |
|---|---|
| ArkUI_EmbeddedComponentOption* option | Pointer to the EmbeddedComponent component option object to be disposed of. It cannot be null and must be a valid object created by OH_ArkUI_EmbeddedComponentOption_Create(). |
void OH_ArkUI_EmbeddedComponentOption_SetOnError(ArkUI_EmbeddedComponentOption* option, void (*callback)(int32_t code, const char* name, const char* message))
Description
Sets the onError callback for the EmbeddedComponent component. This callback is triggered when an error occurs during the running of the EmbeddedComponent component.
Since: 20
Parameters
| Name | Description |
|---|---|
| ArkUI_EmbeddedComponentOption* option | Pointer to the EmbeddedComponent option object. |
| void (*callback)(int32_t code, const char* name, const char* message) | Pointer to a custom callback. If this callback is not set, no callback is triggered when an exception occurs during the running of the EmbeddedComponent component. - code: error code returned when an exception occurs during the running of the component. For details about the error codes, see UIExtension Error Codes. - name: name returned when an exception occurs during the running of the component. - message: detailed information returned when an exception occurs during the running of the component. |
void OH_ArkUI_EmbeddedComponentOption_SetOnTerminated(ArkUI_EmbeddedComponentOption* option, void (*callback)(int32_t code, AbilityBase_Want* want))
Description
Sets the onTerminated callback for the EmbeddedComponent component. This callback is triggered when the EmbeddedComponent component exits properly.
Since: 20
Parameters
| Name | Description |
|---|---|
| ArkUI_EmbeddedComponentOption* option | Pointer to the EmbeddedComponent component option object. |
| void (*callback)(int32_t code, AbilityBase_Want* want) | Pointer to a custom callback. If this callback is not set, it is not triggered when the EmbeddedComponent component exits normally. - code: result code returned when the started EmbeddedUIExtensionAbility exits. If EmbeddedUIExtensionAbility exits by calling terminateSelfWithResult, the result code is the value set by EmbeddedUIExtensionAbility. If EmbeddedUIExtensionAbility exits by calling terminateSelf, the result code is the default value 0. - want: data returned when the started EmbeddedUIExtensionAbility exits. If EmbeddedUIExtensionAbility exits by calling terminateSelfWithResult, the returned data is the data set by EmbeddedUIExtensionAbility. If EmbeddedUIExtensionAbility exits by calling terminateSelf, the returned data is the default value. |