未验证 提交 4226e9a8 编写于 作者: O openharmony_ci 提交者: Gitee

!2105 修复ability资料说明

Merge pull request !2105 from guyuanzhang/fa_docs
......@@ -78,7 +78,7 @@ Ability assistant(Ability助手,简称为aa)是实现应用、原子化服
| -s/--stack \<number> | 打印指定mission stack内的Ability。 |
| -m/--mission \<number> | 打印指定mission内的Ability。 |
| -l/--stack-list | 打印每个mission stack内的mission列表。 |
| -u/--ui | 打印system ui Ability。 |
| -u/--ui | 打印system UI Ability。 |
| -e/--serv | 打印Service Ability。 |
| -d/--data | 打印Data Ability。 |
......
# FA模型综述
\ No newline at end of file
# FA模型综述
## 整体架构
鸿蒙用户程序的开发本质上就是开发Ability,OpenHarmony系统也是通过调度Ability,通过系统提供的一致性调度契约对Ability进行生命周期管理,从而实现对用户程序的调度。FA模型中Ability分为PageAbility、ServiceAbility和DataAbility三种类型。其中PageAbility具备ArkUI的Ability,是用户具体可见并可以交互的Ability实例;ServiceAbility也是Ability一种,但是没有UI,提供其他Ability调用自定义的服务,在后台运行;DataAbility也是没有UI,提供其他Ability进行数据的增删查服务,在后台运行。
## 应用包结构
**应用包结构如下图所示:**
![fa-package-info](figures/fa-package-info.png)
## 生命周期
**pageAbility生命周期回调如下图所示:**
![fa-pageAbility-lifecycle](figures/fa-pageAbility-lifecycle.png)
开发者可以在 app.js/app.ets 中重写生命周期函数,在对应的生命周期函数内处理应用相应逻辑。
## 进程线程模型
应用独享独立进程,Ability独享独立线程,应用进程在Ability第一次启动时创建,并为启动的Ability创建线程,应启动后再启动应用内其他Ability,会创建相应的线程。每个Ability独享一个JSRuntime,因此Ability之间是隔离的。
![fa-threading-nodel](figures/fa-threading-model.png)
\ No newline at end of file
......@@ -27,19 +27,19 @@ Page模板(以下简称“Page”)是FA唯一支持的模板,用于提供
**PageAbility类型Ability生命周期回调如下图所示:**
![PageAbility-Lifecycel-Callbacks](figures/page-ability-lifecycle-callbacks.png)
![fa-pageAbility-lifecycle](figures/fa-pageAbility-lifecycle.png)
## 启动本地PageAbility
导入模块
* 导入模块
```
import featureAbility from '@ohos.ability.featureAbility'
```
```
FeatureAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>)
featureAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>)
```
* 接口说明
......@@ -50,61 +50,75 @@ import featureAbility from '@ohos.ability.featureAbility'
```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.startAbility(
{
want:
{
action: "",
entities: [""],
type: "",
options: {
// indicates the grant to perform read operations on the URI
authReadUriPermission: true,
// indicates the grant to perform write operations on the URI
authWriteUriPermission: true,
// support forward intent result to origin ability
abilityForwardResult: true,
// used for marking the ability start-up is triggered by continuation
abilityContinuation: true,
// specifies whether a component does not belong to ohos
notOhosComponent: true,
// specifies whether an ability is started
abilityFormEnabled: true,
// indicates the grant for possible persisting on the URI.
authPersistableUriPermission: true,
// indicates the grant for possible persisting on the URI.
authPrefixUriPermission: true,
// support distributed scheduling system start up multiple devices
abilitySliceMultiDevice: true,
// indicates that an ability using the service template is started regardless of whether the
// host application has been started.
startForegroundAbility: true,
// install the specified ability if it's not installed.
installOnDemand: true,
// return result to origin ability slice
abilitySliceForwardResult: true,
// install the specified ability with background mode if it's not installed.
installWithBackgroundMode: true
},
deviceId: "",
bundleName: "com.example.startability",
abilityName: "com.example.startability.MainAbility",
uri: ""
},
featureAbility.startAbility({
want:
{
action: "",
entities: [""],
type: "",
options: {
// indicates the grant to perform read operations on the URI
authReadUriPermission: true,
// indicates the grant to perform write operations on the URI
authWriteUriPermission: true,
// support forward intent result to origin ability
abilityForwardResult: true,
// used for marking the ability start-up is triggered by continuation
abilityContinuation: true,
// specifies whether a component does not belong to ohos
notOhosComponent: true,
// specifies whether an ability is started
abilityFormEnabled: true,
// indicates the grant for possible persisting on the URI.
authPersistableUriPermission: true,
// indicates the grant for possible persisting on the URI.
authPrefixUriPermission: true,
// support distributed scheduling system start up multiple devices
abilitySliceMultiDevice: true,
// indicates that an ability using the service template is started regardless of whether the
// host application has been started.
startForegroundAbility: true,
// install the specified ability if it's not installed.
installOnDemand: true,
// return result to origin ability slice
abilitySliceForwardResult: true,
// install the specified ability with background mode if it's not installed.
installWithBackgroundMode: true
},
);
)
deviceId: "",
bundleName: "com.example.startability",
abilityName: "com.example.startability.MainAbility",
uri: ""
},
},
);
```
want参数也可以使用parameters参数,使用key-value的方式输入。
* 示例
```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.startAbility({
want:
{
bundleName: "com.example.startability",
uri: "",
parameters: {
abilityName: "com.example.startability.MainAbility"
}
},
},
);
```
## 启动远程PageAbility
导入模块
* 导入模块
```
import featureAbility from '@ohos.ability.featureAbility'
```
```
FeatureAbility.startAbility(parameter: StartAbilityParameter)
featureAbility.startAbility(parameter: StartAbilityParameter)
```
* 接口说明
......@@ -114,14 +128,13 @@ FeatureAbility.startAbility(parameter: StartAbilityParameter)
* 示例
```javascript
var promise = await ability.startAbility(
{
want:
{
deviceId: this.deviceId,
bundleName: "com.example.test",
abilityName: "com.example.test.MainAbility",
},
}
);
var promise = await featureAbility.startAbility({
want:
{
deviceId: this.deviceId,
bundleName: "com.example.test",
abilityName: "com.example.test.MainAbility",
},
}
);
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册