1e41f4b71Sopenharmony_ci# Lifecycle
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Application lifecycle
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciYou can define the following application lifecycle methods in the **app.js** file.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci| Attribute     | Type      | Description    | Called When          |
9e41f4b71Sopenharmony_ci| --------- | ---------- | -------- | ------------------ |
10e41f4b71Sopenharmony_ci| onCreate  | () => void | Listens for application creation.| The application is created.|
11e41f4b71Sopenharmony_ci| onDestroy | () => void | Listens for application destruction.| The application exits.|
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Page Lifecycle
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciYou can define the following page lifecycle functions in the **.js** file of the page.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci> **NOTE**
18e41f4b71Sopenharmony_ci>
19e41f4b71Sopenharmony_ci> To avoid affecting the page switching performance, do not perform complex, time-consuming operations in a lifecycle function.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci| Attribute     | Type      | Description        | Called When                              |
22e41f4b71Sopenharmony_ci| --------- | ---------- | ------------ | -------------------------------------- |
23e41f4b71Sopenharmony_ci| onInit    | () => void | Listens for page initialization.  | Page initialization is complete. This function is called only once in the page lifecycle.|
24e41f4b71Sopenharmony_ci| onReady   | () => void | Listens for page creation.| A page is created. This function is called only once in the page lifecycle.      |
25e41f4b71Sopenharmony_ci| onShow    | () => void | Listens for page display.    | The page is displayed.                      |
26e41f4b71Sopenharmony_ci| onHide    | () => void | Listens for page hiding.    | The page is hidden.                      |
27e41f4b71Sopenharmony_ci| onDestroy | () => void | Listens for page destruction.    | The page is destroyed.                      |
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ciThe lifecycle functions of page A are called in the following sequence:
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci- Open page A: Call onInit(), onReady(), and onShow() in sequence.
32e41f4b71Sopenharmony_ci- Open page B on page A: onHide() -> onDestroy()
33e41f4b71Sopenharmony_ci- Go back to page A from page B: onInit() -> onReady() -> onShow()
34e41f4b71Sopenharmony_ci- Exit page A: onHide() -> onDestroy()
35e41f4b71Sopenharmony_ci- Hide page A: onHide()
36e41f4b71Sopenharmony_ci- Show background page A on the foreground: onShow()
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci![img](figures/lifecycle.png)
39