• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# FA模型综述
2
3## 整体架构
4
5OpenHarmony应用的开发,是以Ability为入口展开的。
6
7对于Ability的开发,通常是以生命周期的回调处理为中心。
8
9Ability框架在API 8及更早版本仅支持FA模型。FA模型中Ability分为PageAbility、ServiceAbility、DataAbility、FormAbility几种类型。其中:
10- PageAbility使用ArkUI实现用户界面,是用户可见并可以交互的Ability实例。
11- ServiceAbility也是Ability一种,但是没有用户界面。它提供了其他Ability调用的自定义服务,ServiceAbility在后台运行。
12- DataAbility也是没有界面的Ability,提供其他Ability进行数据的增删查服务,它同样在后台运行。
13- FormAbility是实现卡片的Ability,卡片是OpenHarmomny系统上的一种界面展示形式。
14
15> 注:自API 9开始,Stage模型是主推的开发模型。
16
17## 生命周期
18
19在所有Ability中,PageAbility因为具有界面,也是应用的交互入口,因此其生命周期更加复杂。
20**PageAbility生命周期回调如下图所示:**
21
22![fa-pageAbility-lifecycle](figures/fa-pageAbility-lifecycle.png)
23
24其他类型Ability的生命周期可参考PageAbility生命周期去除前后台切换以及`onShow`及`onHide`的部分来理解。
25开发者可以在 `app.js/app.ets` 中重写生命周期函数,在对应的生命周期回调内处理应用的相应逻辑。
26
27目前`app.js`仅支持`onCreate`和`onDestroy`回调,但`app.ets`支持全量生命周期回调。
28
29## 进程线程模型
30
31每个应用运行在不同的进程中,在FA模型中,每个Ability运行在独立的虚拟机中。
32
33应用进程在Ability启动时创建,此时会为Ability创建相应的线程。当一个应用有多个Ability时,每一个Ability在独立线程中运行。在FA模型中,每个Ability绑定一个独立的虚拟机实例,因此Ability之间是隔离的。
34
35![fa-threading-model](figures/fa-threading-model.png)
36
37## 应用包结构
38
39FA模型的应用包的工程目录结构,请参考[OpenHarmony工程介绍](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-project-overview-0000001218440650#section4154183910141)40
41对FA模型的应用包结构的配置说明,请参考[应用包结构说明(FA模型)](../quick-start/application-configuration-file-overview-fa.md)。
42
43
44
45## 相关实例
46
47针对FA模型下的Ability开发,有以下相关实例可供参考:
48
49- [`FaModel`:FA模型(ArkTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony-3.2-Release/ability/FaModel)
50- [`DistributedCalc`:分布式计算器(JS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony-3.2-Release/common/DistributeCalc)
51- [`DistributedCalc`:分布式计算器(ArkTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony-3.2-Release/Preset/DistributeCalc)
52- [`DistributeGraffiti`:分布式涂鸦(ArkTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/OpenHarmony-3.2-Release/ability/DistributedGraffiti)
53- [分布式调度启动远程FA(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/RemoteStartFA)
54- [分布式新闻客户端(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/NewsDemo)
55- [分布式手写板(ArkTS)(Full SDK)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/DistributeDatabaseDrawEts)
56- [分布式鉴权(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/GameAuthOpenH)
57- [分布式游戏手柄(ArkTS)(Full SDK)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/HandleGameApplication)
58- [分布式邮件(ArkTS)(Full SDK)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/OHMailETS)
59- [分布式亲子早教系统(ArkTS)(Full SDK)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/OpenHarmonyPictureGame)
60- [分布式遥控器(ArkTS)(Full SDK)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/RemoteControllerETS)