1e41f4b71Sopenharmony_ci# PageAbility Lifecycle 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThe PageAbility lifecycle defines all states of a PageAbility, such as **INACTIVE**, **ACTIVE**, and **BACKGROUND**. The figure below shows the lifecycle state transition. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci**Figure 1** PageAbility lifecycle 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci**Table 1** PageAbility lifecycle states 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci| State| Description| 13e41f4b71Sopenharmony_ci| -------- | -------- | 14e41f4b71Sopenharmony_ci| UNINITIALIZED | The PageAbility is not initialized. This is a temporary state, from which a PageAbility changes directly to the **INITIAL** state upon its creation.| 15e41f4b71Sopenharmony_ci| INITIAL | The PageAbility is initialized but not running. The PageAbility enters the **INACTIVE** state after it is started.| 16e41f4b71Sopenharmony_ci| INACTIVE | The PageAbility is visible but does not gain focus.| 17e41f4b71Sopenharmony_ci| ACTIVE | The PageAbility runs in the foreground and has focus.| 18e41f4b71Sopenharmony_ci| BACKGROUND | The PageAbility runs in the background. After being re-activated, the PageAbility enters the **ACTIVE** state. After being destroyed, it enters the **INITIAL** state.| 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciYou can implement the lifecycle callbacks (as described in the table below) in **app.js** or **app.ets**. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**Table 2** PageAbility lifecycle callbacks 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci| API| Description| 27e41f4b71Sopenharmony_ci| -------- | -------- | 28e41f4b71Sopenharmony_ci| onCreate() | Called when the ability is created for the first time. You can initialize the application in this callback.| 29e41f4b71Sopenharmony_ci| onDestroy() | Called when the ability is destroyed. In this callback, you can make preparations for application exit, such as recycling resources and clearing the cache.| 30e41f4b71Sopenharmony_ci| onActive() | Called when the ability is switched to the foreground and gains focus.| 31e41f4b71Sopenharmony_ci| onInactive() | Called when the ability loses focus. An ability loses focus when it is about to enter the background state.| 32e41f4b71Sopenharmony_ci| onShow() | Called when the ability is switched from the background to the foreground. In this case, the ability is visible to users.| 33e41f4b71Sopenharmony_ci| onHide() | Called when the ability is switched from the foreground to the background. In this case, the ability is invisible to users.| 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ciThe following figure shows the relationship between lifecycle callbacks and lifecycle states of the PageAbility. 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ciFigure 2 Relationship between lifecycle callbacks and lifecycle states 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci> **NOTE** 44e41f4b71Sopenharmony_ci> 45e41f4b71Sopenharmony_ci> - The PageAbility lifecycle callbacks are synchronous. 46e41f4b71Sopenharmony_ci> - The **app.js** file provides only the **onCreate** and **onDestroy** callbacks, and the **app.ets** file provides the full lifecycle callbacks. 47