1e41f4b71Sopenharmony_ci# Application Framework Overview<a name="EN-US_TOPIC_0000001062225512"></a> 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe application framework is provided by OpenHarmony for you to develop OpenHarmony applications. It consists of two modules: ability management framework \(also called the ability framework\) and bundle management framework. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## Basic Concepts<a name="section72601941194812"></a> 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThis section describes some basic concepts for you to better understand the OpenHarmony application framework before you start development. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Ability Management Framework<a name="section14633111813374"></a> 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciThe ability management framework manages running status of OpenHarmony applications. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Figure 1** Architecture of the ability management framework<a name="fig9759195514371"></a> 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci- **Ability** is the minimum unit for the system to schedule applications. It is a component that can implement an independent functionality. An application can contain one or more **Ability** instances. There are two types of templates that you can use to create an **Ability** instance: Page and Service. 17e41f4b71Sopenharmony_ci - An **Ability using the Page template** \(Page ability for short\) provides a UI for interacting with users. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci - An **Ability using the Service template** does not have a UI and is used for running background tasks. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci- An **AbilitySlice** represents a single screen and its control logic. It is specific to Page abilities. A Page ability may contain one ability slice or multiple ability slices that provide highly relevant capabilities. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci **Figure 2** Relationship between a Page ability and its ability slices<a name="fig1065819910347"></a> 26e41f4b71Sopenharmony_ci  27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci- **Lifecycle** is a general term for all states of an ability, including **INITIAL**, **INACTIVE**, **ACTIVE**, and **BACKGROUND**. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci **Figure 3** Lifecycle state transition of a Page ability<a name="fig56111543375"></a> 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci  34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci - **OnStart\(\)** 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci This callback is invoked when the system first creates the Page ability. After this callback is executed, the Page ability enters the **INACTIVE** state. This callback is triggered only once in the entire lifecycle of each Page ability. You must override this callback and set the default ability slice to be displayed. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci - **OnActive\(\)** 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci This callback is invoked when the Page ability in the **INACTIVE** state enters the foreground. After this callback is executed, the Page ability enters the **ACTIVE** state, in which it becomes interactive. The Page ability will stay in this state unless it loses focus upon a certain event, for example, when the user touches the Back button or navigates to another Page ability. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci When such an event occurs, the Page ability returns to the **INACTIVE** state, and the system invokes the **OnInactive\(\)** callback. The Page ability may move to the **ACTIVE** state again, and the system will then invoke the **OnActive\(\)** callback again. You should implement both **OnActive\(\)** and **OnInactive\(\)** for a Page ability and use **OnActive\(\)** to obtain the resources released in **OnInactive\(\)**. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci - **OnInactive\(\)** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci This callback is invoked when the Page ability loses focus, and the Page ability then becomes **INACTIVE**. You can implement the behavior to perform after the Page ability loses focus. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci - **OnBackground\(\)** 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci This callback is invoked based on the system resource status when the Page ability becomes invisible to the user. After this callback is executed, the Page ability enters the **BACKGROUND** state. You should release the resources that are no longer needed after the Page ability becomes invisible or perform time-consuming save operations in this callback. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci - **OnForeground\(\)** 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci A Page ability in the **BACKGROUND** state still resides in memory. When the Page ability returns to the foreground \(for example, when the user navigates to this Page ability again\), the system first calls **OnForeground\(\)** to switch the Page ability to the **INACTIVE** state, and then calls **OnActive\(\)** to make it **ACTIVE**. You should use the **OnForeground\(\)** callback to reclaim the resources released in **OnBackground\(\)**. Currently, the **OnForeground\(\)** callback is unavailable to lite devices. 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci - **OnStop\(\)** 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci This callback is invoked when the system is destroying a Page ability due to one of the following possible causes: 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci - The user explicitly closes the Page ability using a system management feature, for example, the task manager. 62e41f4b71Sopenharmony_ci - The user behavior, for example, exiting an application, triggers the **TerminateAbility\(\)** function on the Page ability. 63e41f4b71Sopenharmony_ci - The system needs to temporarily destroy the Page ability and re-create it due to configuration changes. 64e41f4b71Sopenharmony_ci - The system automatically destroys a Page ability in the **BACKGROUND** state due to resource management purposes. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci- **AbilityKit** is a development kit provided by the ability management framework. You can use this kit to develop applications based on the **Ability** component. There are two types of applications developed based on the **Ability** component: JS Ability developed using the JavaScript language and Native Ability developed using the C/C++ language. The JS application development framework encapsulates JavaScript UI components on the basis of the AbilityKit and is used to help you quickly develop JS Ability-based applications. 68e41f4b71Sopenharmony_ci- **AbilityLoader** is used to register and load **Ability** classes. After creating an **Ability** class, you should first call the registration API defined in **AbilityLoader** to register the **Ability** class name with the ability management framework so that this **Ability** can be instantiated when being started. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci- **AbilityManager** enables inter-process communication \(IPC\) between the AbilityKit and the Ability Manager Service. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci- **EventHandler** is provided by the AbilityKit to enable inter-thread communication between abilities. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci- The **Ability Manager Service** is a system service used to coordinate the running relationships and lifecycle states of **Ability** instances. It consists of the following modules: 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci - The service startup module starts and registers the Ability Manager Service. 77e41f4b71Sopenharmony_ci - The service interface management module manages external capabilities provided by the Ability Manager Service. 78e41f4b71Sopenharmony_ci - The process management module starts and destroys processes where **Ability** instances are running, and maintains the process information. 79e41f4b71Sopenharmony_ci - The ability stack management module maintains the presentation sequence of abilities in the stack. 80e41f4b71Sopenharmony_ci - The lifecycle scheduling module changes an ability to a particular state based on the current operation of the system. 81e41f4b71Sopenharmony_ci - The connection management module manages connections to Service abilities. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci- **AppSpawn** is a system service used to create the process for running an ability. This service has high permissions. It sets permissions for **Ability** instances and pre-loads some common modules to accelerate application startup. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci## Bundle Management Framework<a name="section1341146154412"></a> 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ciThe bundle management framework is provided by OpenHarmony for you to manage application bundles. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**Figure 4** Architecture of the bundle management framework<a name="fig85883251434"></a> 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci- **BundleKit** includes external APIs provided by the Bundle Manager Service, including the APIs for application installation and uninstallation, bundle information query, and bundle state change listeners. 94e41f4b71Sopenharmony_ci- The **bundle scanning sub-module** parses pre-installed or installed bundles on the local device and extracts information from them for the bundle management module to manage and make the information persistent for storage. 95e41f4b71Sopenharmony_ci- The **bundle installation sub-module** installs, uninstalls, and updates a bundle. The **bundle installation service** is an independent process that communicates with the Bundle Manager Service through IPC. It is used to create or delete installation directories and has high permissions. 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci- The **bundle management sub-module** manages information related to application bundles and stores persistent bundle information. 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci- The **bundle security management sub-module** verifies signatures, and grants and manages permissions. 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci## Working Principles<a name="section94302021112717"></a> 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ciThe Ability Manager Service and Bundle Manager Service are the core modules of the ability management framework and bundle management framework, respectively. The two system-level services are registered and discovered by using the system service framework SAMgr, and they are used by manage abilities and bundles for other processes. The Ability Manager Service and Bundle Manager Service are provided as open APIs in the AbilityKit and BundleKit. 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**Figure 5** Startup of the Ability Manager Service and Bundle Manager Service<a name="fig13121104711910"></a> 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ciOpenHarmony applications can be installed and started after the two services are started. 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**Figure 6** Application startup process<a name="fig756104112311"></a> 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciThe home screen is the first OpenHarmony application started by the Ability Manager Service. After the home screen is started, the user can touch any installed OpenHarmony application on the home screen to start the particular application. The figure above shows the interaction process of starting an installed application from the home screen. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ciAs shown in the figure, the Ability Manager Service is responsible for displaying or hiding an ability, and the Bundle Manager Service is responsible for storing and querying ability information. 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci## Limitations and Constraints<a name="section89534912527"></a> 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci- Language version 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci - C++ 11 or later 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci- The specifications of the application framework vary depending on the System-on-a-Chip \(SoC\) and underlying OS capabilities. 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci - Cortex-M RAM and ROM 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci - RAM: greater than 20 KB \(recommended\) 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci - ROM: greater than 300 KB \(for the JS application development framework and related subsystems, such as UIKit and engine\) 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci - Cortex-A RAM and ROM 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci - RAM: greater than 2 MB \(recommended\) 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci - ROM: greater than 2 MB \(for the JS application development framework and related subsystems, such as UIKit and engine\) 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci 142