# AbilityKit - [Overview](#section2113005606165623) - [Summary](#section50038972165623) - [Files](#files) - [Data Structures](#nested-classes) - [Macros](#define-members) - [Enumerations](#enum-members) - [Functions](#func-members) - [Details](#section268415259165623) - [Macro Definition](#section1597786070165623) - [REGISTER\_AA](#ga2c5bd891b502a92f937ae4bff3f80cad) - [REGISTER\_AS](#ga8e811999b2b7780e67cb746d045ab5b8) - [Enumeration Type](#section1266264770165623) - [anonymous enum](#ga99fb83031ce9923c84392b4e92f956b5) - [State](#ga5d74787dedbc4e11c1ab15bf487e61f8) - [Function](#section1829026629165623) - [ClearWant\(\)](#ga62ca448e092c81497ffdd1f0b1c56938) - [ConnectAbility\(\) \[1/2\]](#ga4da460ac085a8da1c665f317fcde2ba1) - [ConnectAbility\(\) \[2/2\]](#gaae6c2bbb6ab0df92e39c1daad2bd901f) - [DisconnectAbility\(\) \[1/2\]](#ga1d9023597a9889dbb4015565a10f3470) - [DisconnectAbility\(\) \[2/2\]](#ga2769216a4c2654d3297a2fdb4011ea7a) - [Dump\(\)](#ga5330624843c776ebe61366540d32eb92) - [GetBundleName\(\)](#gac893d7c01fabee34f80294e3e026c37d) - [GetCurrentHandler\(\)](#gad26d144aaecd3185be6902e6d7399b9e) - [GetDataPath\(\)](#ga9be6a002714f3fb61b2335dd13ed9787) - [GetSrcPath\(\)](#ga7cead123e67bea6db8a34c8ae100e6c5) - [MsgHandle\(\)](#gab2d208621c7236c3608afb77d8a02966) - [OnActive\(\) \[1/2\]](#ga1a588eb6635e42979e18ac8013f9ea61) - [OnActive\(\) \[2/2\]](#ga3135bfa435f5aaa185f21014a9e86e59) - [OnBackground\(\) \[1/2\]](#ga19217479f8468b525460be156827a524) - [OnBackground\(\) \[2/2\]](#ga8185ad517d94ca99a00917d3d1f10620) - [OnConnect\(\)](#ga88e9dbaaa083be9f06adeea27680ef76) - [OnDisconnect\(\)](#gac17d2b81d661134b63ee74b0212eace6) - [OnInactive\(\) \[1/2\]](#gae050b00aa885765bb6808374be772615) - [OnInactive\(\) \[2/2\]](#gae251a38aa7c0aebd7498eef86deab7c1) - [OnStart\(\) \[1/2\]](#gad3ffda54b710b0b86e54bd6c13efae98) - [OnStart\(\) \[2/2\]](#ga4d016d42397f33c7710db8544581c757) - [OnStop\(\) \[1/2\]](#ga4e1556b780a1271e61328e659fc30eb9) - [OnStop\(\) \[2/2\]](#gaa4145b360bbe5cdb5d267b17ac12af6a) - [PostTask\(\)](#gad4d0911a8bccd5aca32464bad867cb13) - [Present\(\)](#gab2ec8b885edd0d5818b4c60541c1875f) - [SetMainRoute\(\)](#gac83a9af046458b7f6bfaf85071b093f4) - [SetUIContent\(\) \[1/2\]](#ga050a81cda49edb471594447f8f4cdaac) - [SetUIContent\(\) \[2/2\]](#ga9b734c2ad8ad52f906d676f0c897a4aa) - [SetWantData\(\)](#ga89a719b5f730bc5fde9f637a5ed630c9) - [SetWantElement\(\)](#ga65f4d2eab99497e496dcd493bd0d047e) - [SetWantSvcIdentity\(\)](#gab8e5fac952fc6407f20cd9b7185d3a65) - [StartAbility\(\) \[1/2\]](#gab11d708d5eaa1eca54828fa88625681a) - [StartAbility\(\) \[2/2\]](#gae79800c4077afdc2851d5a74d8964111) - [StopAbility\(\) \[1/2\]](#gadc670d5f6df0d485ee3062b70b3ffe99) - [StopAbility\(\) \[2/2\]](#gaba99bbd4ff6da4fb072338f5ce95e6ae) - [Terminate\(\)](#gaf424e47c7980ff92093c6b7b75888639) - [TerminateAbility\(\)](#gac4a36f03c60fcbeca3b47192ccab1d24) - [WantParseUri\(\)](#ga43226d0858faa92e83bea33aaf4b614c) - [WantToUri\(\)](#ga31adc60981c10b22d0e9bbdc7126d17c) - [Variable](#section1912686851165623) - [OnAbilityConnectDone](#ga3b9bfacbcf1564c83cffbfff7889998a) - [OnAbilityDisconnectDone](#gaba7cf0abb517890ef1a3949e398aaf1d) ## **Overview** **Description:** Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or disconnecting from Particle Abilities. Abilities are classified into [Feature](Feature.md) Abilities and Particle Abilities. [Feature](Feature.md) Abilities support the Page template, and Particle Abilities support the [Service](Service.md) template. An ability using the Page template is called a Page ability for short and that using the [Service](Service.md) template is called a [Service](Service.md) ability. **Since:** 1.0 **Version:** 1.0 ## **Summary** ## Files
Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to or disconnecting from Particle Abilities. |
|
Declares callbacks to be invoked when a remote Service ability is connected or disconnected. |
|
Declares functions for obtaining information about the runtime environment of the application to which the ability belongs, including the bundle name, source code path, and data path. |
|
Declares error codes returned by ability management functions. |
|
Declares functions for performing operations during inter-thread communication, including running and quitting the event loop of the current thread and posting tasks to an asynchronous thread. |
|
Declares functions for registering the class names of Ability and AbilitySlice with the ability management framework. |
|
Declares ability-related functions, including functions for starting, stopping, connecting to, and disconnecting from an ability, registering a callback, and unregistering a callback. |
|
Declares ability slice-related functions, including ability slice lifecycle callbacks and functions for connecting to or disconnecting from ability slices. |
|
Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to or disconnecting from Particle Abilities. As the fundamental unit of OpenHarmony applications, abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template, and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for short and that using the Service template is called a Service ability. |
|
Declares the structure that provides abstract description of the operation to be performed, including the ability information and the carried data, and functions for setting data in the structure. |
Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to or disconnecting from Particle Abilities. |
|
Provides callbacks to be invoked when a remote Service ability is connected or disconnected. |
|
Declares functions for performing operations during inter-thread communication, including running and quitting the event loop of the current thread and posting tasks to an asynchronous thread. |
|
Declares functions for registering the class names of Ability and AbilitySlice with the ability management framework. |
|
Provides ability slice-related functions, including ability slice lifecycle callbacks and functions for connecting to or disconnecting from ability slices. |
|
Defines the abstract description of an operation, including information about the ability and the extra data to carry. |
REGISTER_AA(className) |
|
REGISTER_AS(className) |
{ ERR_OK = 0, PARAM_NULL_ERROR, MEMORY_MALLOC_ERROR, DUMP_ABILITIES_ERROR, IPC_REQUEST_ERROR, SERIALIZE_ERROR, COMMAND_ERROR = 0x7fff } |
Declares error codes returned by ability management functions. |
State { STATE_UNINITIALIZED, STATE_INITIAL, STATE_INACTIVE, STATE_ACTIVE, STATE_BACKGROUND } |
Enumerates all lifecycle states that an ability will go through over the course of its lifetime. |
OHOS::Ability::OnStart (const Want &want) |
Called when this ability is started. You must override this function if you want to perform some initialization operations during ability startup. |
OHOS::Ability::OnActive (const Want &want) |
|
OHOS::Ability::OnConnect (const Want &want) |
Called when this Service ability is connected for the first time. |
OHOS::Ability::OnDisconnect (const Want &want) |
Called when all abilities connected to this Service ability are disconnected. |
OHOS::Ability::SetMainRoute (const std::string &entry) |
|
OHOS::Ability::SetUIContent (RootView *rootView) |
Sets the UI layout for this ability. You can call GetWindowRootView() to create a layout and add controls. |
OHOS::Ability::MsgHandle (uint32_t funcId, IpcIo *request, IpcIo *reply) |
Handles a message sent by the client to this Service ability. |
OHOS::Ability::Dump (const std::string &extra) |
|
OHOS::AbilityContext::StartAbility (const Want &want) |
|
OHOS::AbilityContext::StopAbility (const Want &want) |
|
|
Destroys this Ability. |
|
OHOS::AbilityContext::ConnectAbility (const Want &want, const IAbilityConnection &conn, void *data) |
Connects to a Service ability based on the specified Want information. |
OHOS::AbilityContext::DisconnectAbility (const IAbilityConnection &conn) |
Disconnects from a Service ability. |
|
Obtains the bundle name of the application to which this ability belongs. |
|
GetSrcPath () |
|
GetDataPath () |
|
OHOS::AbilityEventHandler::PostTask (const Task &task) |
|
static AbilityEventHandler * |
|
StartAbility (const Want *want) |
Starts an ability based on the specified Want information. |
StopAbility (const Want *want) |
Stops an ability based on the specified Want information. |
ConnectAbility (const Want *want, const IAbilityConnection *conn, void *data) |
Connects to a Service ability based on the specified Want information. |
DisconnectAbility (const IAbilityConnection *conn) |
Disconnects from a Service ability. |
OHOS::AbilitySlice::OnStart (const Want &want) |
Called when this ability slice is started. You must override this function if you want to perform some initialization operations during ability slice startup. |
|
Called when this ability slice enters the STATE_INACTIVE state. |
|
OHOS::AbilitySlice::OnActive (const Want &want) |
Called when this ability slice enters the STATE_ACTIVE state. |
|
Called when this ability slice enters the STATE_BACKGROUND state. |
|
OHOS::AbilitySlice::Present (AbilitySlice &abilitySlice, const Want &want) |
Presents another ability slice, which can be an ability slice that is not started or an existing ability slice in the host ability. |
OHOS::AbilitySlice::SetUIContent (RootView *rootView) |
Sets the UI layout for the host ability of this ability slice. |
|
Clears the memory of a specified Want object. |
|
SetWantElement (Want *want, ElementName element) |
Sets the element variable for a specified Want object. |
SetWantData (Want *want, const void *data, uint16_t dataLength) |
Sets data to carry in a specified Want object for starting a particular ability. |
SetWantSvcIdentity (Want *want, SvcIdentity sid) |
Sets the sid member variable for a specified Want object. |
|
Converts a specified Want object into a character string. |
|
WantParseUri (const char *uri) |
Want * Converts a specified character string into a Want object. |
| className | Indicates the Ability class name to register. |
| className | Indicates the AbilitySlice class name to register. |
| ERR_OK | |
| PARAM_NULL_ERROR | |
| MEMORY_MALLOC_ERROR | |
| DUMP_ABILITIES_ERROR | An error occurred during the execution of the Dump function. |
| IPC_REQUEST_ERROR | |
| SERIALIZE_ERROR | |
| COMMAND_ERROR |
| want | Indicates the pointer to the Want object whose memory is to be released. |
| want | Indicates the pointer to the Want structure containing information about the Service ability to connect. |
| conn | Indicates the callback to be invoked when the connection is successful. |
| data | Indicates the pointer to the data to be passed to the callback. |
| want | Indicates the pointer to the Want structure containing information about the Service ability to connect. |
| conn | Indicates the callback object when the Service ability is connected. |
| data | Indicates the pointer to the data to be passed to the callback. |
| conn | Indicates the callback to be invoked when the connection is successful. |
| conn | Indicates the callback object when the Service ability is connected. |
| extra | Indicates the extra parameter to be obtained or printed to the console. |
| funcId | Indicates the type of the message sent by the client. |
| request | Indicates the pointer to the serialized request parameters sent by the client. |
| reply | Indicates the pointer to the serialized result returned to the client. |
| want | Indicates the Want structure containing activation information about the ability slice. |
| want | Indicates the Want structure containing activation information about the ability. |
| want | Indicates the Want structure containing connection information about the Service ability. |
| want | Indicates the Want structure containing disconnection information about the Service ability. |
| want | Indicates the Want structure containing startup information about the ability slice. |
| want | Indicates the Want structure containing startup information about the ability. |
| task | Indicates the task to post. |
| abilitySlice | Indicates the target ability slice. This parameter cannot be null. |
| want | Indicates the Want structure containing startup information about the target ability slice. |
| entry | Indicates the main entry, which is the class name of the AbilitySlice instance to start. |
| rootView | Indicates the pointer to the custom layout view you have created. |
| rootView | Indicates the pointer to the custom layout view you have created. |
| want | Indicates the pointer to the Want object to set. |
| data | Indicates the pointer to the data to set. |
| dataLength | Indicates the data length to set. The length must be the same as that of the data specified in data. |
| want | Indicates the pointer to the Want object to set. |
| element | Indicates the ElementName containing information required for starting the ability. |
| want | Indicates the pointer to the Want object to set. |
| sid | Indicates the SvcIdentity object to set. |
| want | Indicates the pointer to the Want structure containing information about the ability to start. |
| want | Indicates the pointer to the Want structure containing information about the ability to start. |
| want | Indicates the pointer to the Want structure containing information about the ability to stop. |
| want | Indicates the pointer to the Want structure containing information about the ability to stop. |
| uri | Indicates the pointer to the character string to convert. |
| want | Indicates the Want object to convert. |
| elementName | Indicates the pointer to the information about the connected Service ability. |
| serviceSid | Indicates the pointer to the remote proxy object of the Service ability. |
| resultCode | Indicates the connection result code. The value 0 indicates a successful connection, and any other value indicates a connection failure. |
| data | Indicates the pointer to the data stored during the connection. |
| elementName | Indicates the pointer to the information about the disconnected Service ability. |
| resultCode | Indicates the disconnection result code. The value 0 indicates a successful disconnection, and any other value indicates a disconnection failure. |
| data | Indicates the pointer to the data stored during the connection. |