目录

Application Startup Process

Overview

Application startup refers to the process in which a user triggers the system to launch an application through an entry point (such as an application icon or shortcut). In the application model, a typical application startup sequentially goes through three phases: process startup, AbilityStage startup, and UIAbility startup, during which the corresponding lifecycle callbacks are triggered. Understanding the relationships and timing among the three helps developers complete initialization, resource requests, and UI loading at the correct time.

The relationship among the process, AbilityStage, and UIAbility lifecycles is shown in the following figure.

Phase Trigger Timing Main Responsibilities
Process startup When the first process of the application is created Allocate system resources, create the main thread, and load the application runtime environment
AbilityStage startup When the HAP is loaded for the first time and before the first application component instance is created Module-level initialization, such as resource preloading, thread creation, and startup framework task execution
UIAbility startup When a UIAbility instance is created and displayed Instance-level initialization, UI loading, and foreground/background resource request and release

Recommendations for Using Callbacks in Startup Phases

[h2]Module-Level Initialization (AbilityStage.onCreate)

As described in Overview, the system first creates the AbilityStage and executes its onCreate() callback. This callback is triggered only once in the lifecycle of each HAP, making it suitable for placing Module-level initialization logic.

Recommended in this callback:

Not recommended in this callback:

[h2]Specified Instance Mode Routing (AbilityStage.onAcceptWant)

When a UIAbility specified instance mode (specified) is started, the system triggers the onAcceptWant() callback of AbilityStage, and the developer returns an instance key to determine whether to reuse an existing UIAbility instance or create a new one.

Recommended in this callback:

Not recommended in this callback:

[h2]UIAbility Instance Initialization (UIAbility.onCreate)

This callback is triggered only once in the entire lifecycle of a UIAbility instance. Developers can execute startup logic that occurs only once in this callback.

Recommended in this callback:

Not recommended in this callback:

Startup Entry

The startup entry of an application refers to the way a user enters the application (such as the application icon, shortcut, and so on). When different entries trigger UIAbility startup, the Want parameters (such as action, uri, and parameters) passed by the system may differ. Developers can distinguish the source based on these parameters in onCreate() or onNewWant() of UIAbility and execute the corresponding logic.

An application can also be pulled up by other applications through Want or application links, or be scheduled and started by the system through the intent framework. For details about such cross-application startup scenarios, see Cross-Application Navigation.

[h2]Application Icon (Desktop Icon)

The application icon is the most common entry point for application startup, typically displayed on the system desktop. When the user taps the desktop icon, the system initiates startup based on the entry UIAbility declared in the module.json5 configuration file (usually the UIAbility corresponding to startWindowIcon and label in the entry-type HAP).

[h2]Shortcut

A shortcut is a quick menu item that appears when you press and hold an application icon, allowing users to directly jump to a specific feature page of the application. Developers can declare static shortcuts in the shortcuts tag of the module.json5 configuration file, or dynamically publish shortcuts through the shortcutManager API.